Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

refactor: incorporate eth-hash-to-cid module #19

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth-account-snapshot/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const EthAccount = require('ethereumjs-account')
const cidFromHash = require('eth-hash-to-cid')
const cidFromHash = require('../util/cidFromHash')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the convention of - instead of Camel Case for filenames.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it in favour of consistency. All files in util are camel case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

favor consistency across modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally yes, but in this case favour local consistency. I've opened an issue for global consistency: #20

const createResolver = require('../util/createResolver')
const emptyCodeHash = require('../util/emptyCodeHash')

Expand Down
2 changes: 1 addition & 1 deletion eth-block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const asyncify = require('async/asyncify')
const RLP = require('rlp')
const EthBlockHead = require('ethereumjs-block/header')
const multihash = require('multihashing-async')
const cidFromHash = require('eth-hash-to-cid')
const cidFromHash = require('../util/cidFromHash')
const ethBlockResolver = require('../eth-block').resolver
const createResolver = require('../util/createResolver')

Expand Down
2 changes: 1 addition & 1 deletion eth-block/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const EthBlockHeader = require('ethereumjs-block/header')
const cidFromHash = require('eth-hash-to-cid')
const cidFromHash = require('../util/cidFromHash')
const createResolver = require('../util/createResolver')

module.exports = createResolver('eth-block', EthBlockHeader, mapFromEthObj)
Expand Down
2 changes: 1 addition & 1 deletion eth-state-trie/test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Trie = require('merkle-patricia-tree')
const TrieNode = require('merkle-patricia-tree/trieNode')
const multihashing = require('multihashing-async')
const CID = require('cids')
const cidFromHash = require('eth-hash-to-cid')
const cidFromHash = require('../../util/cidFromHash')
const ipldEthStateTrie = require('../index')
const isExternalLink = require('../../util/isExternalLink')
const resolver = ipldEthStateTrie.resolver
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"dependencies": {
"async": "^2.6.0",
"cids": "~0.5.2",
"eth-hash-to-cid": "~0.1.0",
"ethereumjs-account": "^2.0.4",
"ethereumjs-block": "^1.7.1",
"ethereumjs-tx": "^1.3.3",
Expand Down
2 changes: 1 addition & 1 deletion util/cidFromEthObj.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const cidFromHash = require('eth-hash-to-cid')
const cidFromHash = require('./cidFromHash')

module.exports = cidFromEthObj

Expand Down
12 changes: 12 additions & 0 deletions util/cidFromHash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

const CID = require('cids')
const multihashes = require('multihashes')

module.exports = cidFromHash

function cidFromHash (codec, rawhash) {
const multihash = multihashes.encode(rawhash, 'keccak-256')
const cidVersion = 1
return new CID(cidVersion, codec, multihash)
}
2 changes: 1 addition & 1 deletion util/createTrieResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const waterfall = require('async/waterfall')
const asyncify = require('async/asyncify')
const rlp = require('rlp')
const EthTrieNode = require('merkle-patricia-tree/trieNode')
const cidFromHash = require('eth-hash-to-cid')
const cidFromHash = require('./cidFromHash')
// const createBaseTrieResolver = require('./createBaseTrieResolver.js')
const createResolver = require('./createResolver')
const isExternalLink = require('./isExternalLink')
Expand Down