Skip to content

Commit 6ca2617

Browse files
committed
refactor: remove Codecs table
People should use https://github.com/multiformats/go-multicodec instead.
1 parent da55247 commit 6ca2617

File tree

2 files changed

+0
-131
lines changed

2 files changed

+0
-131
lines changed

cid.go

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,9 @@ const (
5858
DagJSON = 0x0129 // https://ipld.io/docs/codecs/known/dag-json/
5959
Libp2pKey = 0x72 // https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#peer-ids
6060

61-
// generic, non-dag variants
62-
Protobuf = 0x50
63-
CBOR = 0x51
64-
JSON = 0x0200
65-
6661
// other
6762
GitRaw = 0x78
6863
DagJOSE = 0x85 // https://ipld.io/specs/codecs/dag-jose/spec/
69-
DagCOSE = 0x86
7064
EthBlock = 0x90
7165
EthBlockList = 0x91
7266
EthTxTrie = 0x92
@@ -88,75 +82,6 @@ const (
8882
FilCommitmentSealed = 0xf102
8983
)
9084

91-
// Codecs maps the name of a codec to its type
92-
var Codecs = map[string]uint64{
93-
"v0": DagProtobuf, // TODO: remove?
94-
"raw": Raw,
95-
"dag-pb": DagProtobuf,
96-
"dag-cbor": DagCBOR,
97-
"dag-json": DagJSON,
98-
"libp2p-key": Libp2pKey,
99-
"protobuf": Protobuf,
100-
"cbor": CBOR,
101-
"json": JSON,
102-
"git-raw": GitRaw,
103-
"eth-block": EthBlock,
104-
"eth-block-list": EthBlockList,
105-
"eth-tx-trie": EthTxTrie,
106-
"eth-tx": EthTx,
107-
"eth-tx-receipt-trie": EthTxReceiptTrie,
108-
"eth-tx-receipt": EthTxReceipt,
109-
"eth-state-trie": EthStateTrie,
110-
"eth-account-snapshot": EthAccountSnapshot,
111-
"eth-storage-trie": EthStorageTrie,
112-
"bitcoin-block": BitcoinBlock,
113-
"bitcoin-tx": BitcoinTx,
114-
"zcash-block": ZcashBlock,
115-
"zcash-tx": ZcashTx,
116-
"decred-block": DecredBlock,
117-
"decred-tx": DecredTx,
118-
"dash-block": DashBlock,
119-
"dash-tx": DashTx,
120-
"fil-commitment-unsealed": FilCommitmentUnsealed,
121-
"fil-commitment-sealed": FilCommitmentSealed,
122-
"dag-jose": DagJOSE,
123-
"dag-cose": DagCOSE,
124-
}
125-
126-
// CodecToStr maps the numeric codec to its name
127-
var CodecToStr = map[uint64]string{
128-
Raw: "raw",
129-
DagProtobuf: "dag-pb",
130-
DagCBOR: "dag-cbor",
131-
DagJSON: "dag-json",
132-
Libp2pKey: "libp2p-key",
133-
Protobuf: "protobuf",
134-
CBOR: "cbor",
135-
JSON: "json",
136-
GitRaw: "git-raw",
137-
EthBlock: "eth-block",
138-
EthBlockList: "eth-block-list",
139-
EthTxTrie: "eth-tx-trie",
140-
EthTx: "eth-tx",
141-
EthTxReceiptTrie: "eth-tx-receipt-trie",
142-
EthTxReceipt: "eth-tx-receipt",
143-
EthStateTrie: "eth-state-trie",
144-
EthAccountSnapshot: "eth-account-snapshot",
145-
EthStorageTrie: "eth-storage-trie",
146-
BitcoinBlock: "bitcoin-block",
147-
BitcoinTx: "bitcoin-tx",
148-
ZcashBlock: "zcash-block",
149-
ZcashTx: "zcash-tx",
150-
DecredBlock: "decred-block",
151-
DecredTx: "decred-tx",
152-
DashBlock: "dash-block",
153-
DashTx: "dash-tx",
154-
FilCommitmentUnsealed: "fil-commitment-unsealed",
155-
FilCommitmentSealed: "fil-commitment-sealed",
156-
DagJOSE: "dag-jose",
157-
DagCOSE: "dag-cose",
158-
}
159-
16085
// tryNewCidV0 tries to convert a multihash into a CIDv0 CID and returns an
16186
// error on failure.
16287
func tryNewCidV0(mhash mh.Multihash) (Cid, error) {

cid_test.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,6 @@ import (
1515
mh "github.com/multiformats/go-multihash"
1616
)
1717

18-
// Copying the "silly test" idea from
19-
// https://github.com/multiformats/go-multihash/blob/7aa9f26a231c6f34f4e9fad52bf580fd36627285/multihash_test.go#L13
20-
// Makes it so changing the table accidentally has to happen twice.
21-
var tCodecs = map[uint64]string{
22-
Raw: "raw",
23-
DagProtobuf: "dag-pb",
24-
DagCBOR: "dag-cbor",
25-
DagJSON: "dag-json",
26-
Libp2pKey: "libp2p-key",
27-
Protobuf: "protobuf",
28-
CBOR: "cbor",
29-
JSON: "json",
30-
GitRaw: "git-raw",
31-
EthBlock: "eth-block",
32-
EthBlockList: "eth-block-list",
33-
EthTxTrie: "eth-tx-trie",
34-
EthTx: "eth-tx",
35-
EthTxReceiptTrie: "eth-tx-receipt-trie",
36-
EthTxReceipt: "eth-tx-receipt",
37-
EthStateTrie: "eth-state-trie",
38-
EthAccountSnapshot: "eth-account-snapshot",
39-
EthStorageTrie: "eth-storage-trie",
40-
BitcoinBlock: "bitcoin-block",
41-
BitcoinTx: "bitcoin-tx",
42-
ZcashBlock: "zcash-block",
43-
ZcashTx: "zcash-tx",
44-
DecredBlock: "decred-block",
45-
DecredTx: "decred-tx",
46-
DashBlock: "dash-block",
47-
DashTx: "dash-tx",
48-
FilCommitmentUnsealed: "fil-commitment-unsealed",
49-
FilCommitmentSealed: "fil-commitment-sealed",
50-
DagJOSE: "dag-jose",
51-
DagCOSE: "dag-cose",
52-
}
53-
5418
func assertEqual(t *testing.T, a, b Cid) {
5519
if a.Type() != b.Type() {
5620
t.Fatal("mismatch on type")
@@ -65,26 +29,6 @@ func assertEqual(t *testing.T, a, b Cid) {
6529
}
6630
}
6731

68-
func TestTable(t *testing.T) {
69-
if len(tCodecs) != len(Codecs)-1 {
70-
t.Errorf("Item count mismatch in the Table of Codec. Should be %d, got %d", len(tCodecs)+1, len(Codecs))
71-
}
72-
73-
for k, v := range tCodecs {
74-
if Codecs[v] != k {
75-
t.Errorf("Table mismatch: 0x%x %s", k, v)
76-
}
77-
}
78-
}
79-
80-
// The table returns cid.DagProtobuf for "v0"
81-
// so we test it apart
82-
func TestTableForV0(t *testing.T) {
83-
if Codecs["v0"] != DagProtobuf {
84-
t.Error("Table mismatch: Codecs[\"v0\"] should resolve to DagProtobuf (0x70)")
85-
}
86-
}
87-
8832
func TestPrefixSum(t *testing.T) {
8933
// Test creating CIDs both manually and with Prefix.
9034
// Tests: https://github.com/ipfs/go-cid/issues/83

0 commit comments

Comments
 (0)