Skip to content

Commit 95a7ed4

Browse files
authored
Merge pull request #104 from rvagg/rvagg/filecoin-codecs
feat: add Filecoin multicodecs
2 parents a25d68f + 8dd6fe2 commit 95a7ed4

File tree

2 files changed

+91
-83
lines changed

2 files changed

+91
-83
lines changed

cid.go

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -58,75 +58,81 @@ const (
5858

5959
GitRaw = 0x78
6060

61-
EthBlock = 0x90
62-
EthBlockList = 0x91
63-
EthTxTrie = 0x92
64-
EthTx = 0x93
65-
EthTxReceiptTrie = 0x94
66-
EthTxReceipt = 0x95
67-
EthStateTrie = 0x96
68-
EthAccountSnapshot = 0x97
69-
EthStorageTrie = 0x98
70-
BitcoinBlock = 0xb0
71-
BitcoinTx = 0xb1
72-
ZcashBlock = 0xc0
73-
ZcashTx = 0xc1
74-
DecredBlock = 0xe0
75-
DecredTx = 0xe1
76-
DashBlock = 0xf0
77-
DashTx = 0xf1
61+
EthBlock = 0x90
62+
EthBlockList = 0x91
63+
EthTxTrie = 0x92
64+
EthTx = 0x93
65+
EthTxReceiptTrie = 0x94
66+
EthTxReceipt = 0x95
67+
EthStateTrie = 0x96
68+
EthAccountSnapshot = 0x97
69+
EthStorageTrie = 0x98
70+
BitcoinBlock = 0xb0
71+
BitcoinTx = 0xb1
72+
ZcashBlock = 0xc0
73+
ZcashTx = 0xc1
74+
DecredBlock = 0xe0
75+
DecredTx = 0xe1
76+
DashBlock = 0xf0
77+
DashTx = 0xf1
78+
FilCommitmentUnsealed = 0xf101
79+
FilCommitmentSealed = 0xf102
7880
)
7981

8082
// Codecs maps the name of a codec to its type
8183
var Codecs = map[string]uint64{
82-
"v0": DagProtobuf,
83-
"raw": Raw,
84-
"protobuf": DagProtobuf,
85-
"cbor": DagCBOR,
86-
"libp2p-key": Libp2pKey,
87-
"git-raw": GitRaw,
88-
"eth-block": EthBlock,
89-
"eth-block-list": EthBlockList,
90-
"eth-tx-trie": EthTxTrie,
91-
"eth-tx": EthTx,
92-
"eth-tx-receipt-trie": EthTxReceiptTrie,
93-
"eth-tx-receipt": EthTxReceipt,
94-
"eth-state-trie": EthStateTrie,
95-
"eth-account-snapshot": EthAccountSnapshot,
96-
"eth-storage-trie": EthStorageTrie,
97-
"bitcoin-block": BitcoinBlock,
98-
"bitcoin-tx": BitcoinTx,
99-
"zcash-block": ZcashBlock,
100-
"zcash-tx": ZcashTx,
101-
"decred-block": DecredBlock,
102-
"decred-tx": DecredTx,
103-
"dash-block": DashBlock,
104-
"dash-tx": DashTx,
84+
"v0": DagProtobuf,
85+
"raw": Raw,
86+
"protobuf": DagProtobuf,
87+
"cbor": DagCBOR,
88+
"libp2p-key": Libp2pKey,
89+
"git-raw": GitRaw,
90+
"eth-block": EthBlock,
91+
"eth-block-list": EthBlockList,
92+
"eth-tx-trie": EthTxTrie,
93+
"eth-tx": EthTx,
94+
"eth-tx-receipt-trie": EthTxReceiptTrie,
95+
"eth-tx-receipt": EthTxReceipt,
96+
"eth-state-trie": EthStateTrie,
97+
"eth-account-snapshot": EthAccountSnapshot,
98+
"eth-storage-trie": EthStorageTrie,
99+
"bitcoin-block": BitcoinBlock,
100+
"bitcoin-tx": BitcoinTx,
101+
"zcash-block": ZcashBlock,
102+
"zcash-tx": ZcashTx,
103+
"decred-block": DecredBlock,
104+
"decred-tx": DecredTx,
105+
"dash-block": DashBlock,
106+
"dash-tx": DashTx,
107+
"fil-commitment-unsealed": FilCommitmentUnsealed,
108+
"fil-commitment-sealed": FilCommitmentSealed,
105109
}
106110

107111
// CodecToStr maps the numeric codec to its name
108112
var CodecToStr = map[uint64]string{
109-
Raw: "raw",
110-
DagProtobuf: "protobuf",
111-
DagCBOR: "cbor",
112-
GitRaw: "git-raw",
113-
EthBlock: "eth-block",
114-
EthBlockList: "eth-block-list",
115-
EthTxTrie: "eth-tx-trie",
116-
EthTx: "eth-tx",
117-
EthTxReceiptTrie: "eth-tx-receipt-trie",
118-
EthTxReceipt: "eth-tx-receipt",
119-
EthStateTrie: "eth-state-trie",
120-
EthAccountSnapshot: "eth-account-snapshot",
121-
EthStorageTrie: "eth-storage-trie",
122-
BitcoinBlock: "bitcoin-block",
123-
BitcoinTx: "bitcoin-tx",
124-
ZcashBlock: "zcash-block",
125-
ZcashTx: "zcash-tx",
126-
DecredBlock: "decred-block",
127-
DecredTx: "decred-tx",
128-
DashBlock: "dash-block",
129-
DashTx: "dash-tx",
113+
Raw: "raw",
114+
DagProtobuf: "protobuf",
115+
DagCBOR: "cbor",
116+
GitRaw: "git-raw",
117+
EthBlock: "eth-block",
118+
EthBlockList: "eth-block-list",
119+
EthTxTrie: "eth-tx-trie",
120+
EthTx: "eth-tx",
121+
EthTxReceiptTrie: "eth-tx-receipt-trie",
122+
EthTxReceipt: "eth-tx-receipt",
123+
EthStateTrie: "eth-state-trie",
124+
EthAccountSnapshot: "eth-account-snapshot",
125+
EthStorageTrie: "eth-storage-trie",
126+
BitcoinBlock: "bitcoin-block",
127+
BitcoinTx: "bitcoin-tx",
128+
ZcashBlock: "zcash-block",
129+
ZcashTx: "zcash-tx",
130+
DecredBlock: "decred-block",
131+
DecredTx: "decred-tx",
132+
DashBlock: "dash-block",
133+
DashTx: "dash-tx",
134+
FilCommitmentUnsealed: "fil-commitment-unsealed",
135+
FilCommitmentSealed: "fil-commitment-sealed",
130136
}
131137

132138
// tryNewCidV0 tries to convert a multihash into a CIDv0 CID and returns an

cid_test.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,30 @@ import (
1616
// https://github.com/multiformats/go-multihash/blob/7aa9f26a231c6f34f4e9fad52bf580fd36627285/multihash_test.go#L13
1717
// Makes it so changing the table accidentally has to happen twice.
1818
var tCodecs = map[uint64]string{
19-
Raw: "raw",
20-
DagProtobuf: "protobuf",
21-
DagCBOR: "cbor",
22-
Libp2pKey: "libp2p-key",
23-
GitRaw: "git-raw",
24-
EthBlock: "eth-block",
25-
EthBlockList: "eth-block-list",
26-
EthTxTrie: "eth-tx-trie",
27-
EthTx: "eth-tx",
28-
EthTxReceiptTrie: "eth-tx-receipt-trie",
29-
EthTxReceipt: "eth-tx-receipt",
30-
EthStateTrie: "eth-state-trie",
31-
EthAccountSnapshot: "eth-account-snapshot",
32-
EthStorageTrie: "eth-storage-trie",
33-
BitcoinBlock: "bitcoin-block",
34-
BitcoinTx: "bitcoin-tx",
35-
ZcashBlock: "zcash-block",
36-
ZcashTx: "zcash-tx",
37-
DecredBlock: "decred-block",
38-
DecredTx: "decred-tx",
39-
DashBlock: "dash-block",
40-
DashTx: "dash-tx",
19+
Raw: "raw",
20+
DagProtobuf: "protobuf",
21+
DagCBOR: "cbor",
22+
Libp2pKey: "libp2p-key",
23+
GitRaw: "git-raw",
24+
EthBlock: "eth-block",
25+
EthBlockList: "eth-block-list",
26+
EthTxTrie: "eth-tx-trie",
27+
EthTx: "eth-tx",
28+
EthTxReceiptTrie: "eth-tx-receipt-trie",
29+
EthTxReceipt: "eth-tx-receipt",
30+
EthStateTrie: "eth-state-trie",
31+
EthAccountSnapshot: "eth-account-snapshot",
32+
EthStorageTrie: "eth-storage-trie",
33+
BitcoinBlock: "bitcoin-block",
34+
BitcoinTx: "bitcoin-tx",
35+
ZcashBlock: "zcash-block",
36+
ZcashTx: "zcash-tx",
37+
DecredBlock: "decred-block",
38+
DecredTx: "decred-tx",
39+
DashBlock: "dash-block",
40+
DashTx: "dash-tx",
41+
FilCommitmentUnsealed: "fil-commitment-unsealed",
42+
FilCommitmentSealed: "fil-commitment-sealed",
4143
}
4244

4345
func assertEqual(t *testing.T, a, b Cid) {

0 commit comments

Comments
 (0)