Update golint warnings
arnaucube root@arnaucube.com
Tue, 30 Jun 2020 22:44:51 +0200
4 files changed,
15 insertions(+),
5 deletions(-)
M
README.md
→
README.md
@@ -1,4 +1,5 @@
-# go-merkletree +# go-merkletree [](https://goreportcard.com/report/github.com/iden3/go-merkletree) + MerkleTree compatible with version from [circomlib](https://github.com/iden3/circomlib). Adaptation of the merkletree from https://github.com/iden3/go-iden3-core/tree/v0.0.8
M
merkletree.go
→
merkletree.go
@@ -46,26 +46,31 @@ // exists in the tree.
ErrEntryIndexAlreadyExists = errors.New("the entry index already exists in the tree") // ErrNotWritable is used when the MerkleTree is not writable and a write function is called ErrNotWritable = errors.New("Merkle Tree not writable") - - rootNodeValue = []byte("currentroot") - HashZero = Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + rootNodeValue = []byte("currentroot") + // HashZero is used at Empty nodes + HashZero = Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ) +// Hash is the generic type stored in the MerkleTree type Hash [32]byte func (h Hash) String() string { return new(big.Int).SetBytes(h[:]).String() } + +// BigInt returns the *big.Int representation of the *Hash func (h *Hash) BigInt() *big.Int { return new(big.Int).SetBytes(common.SwapEndianness(h[:])) } +// NewHashFromBigInt returns a *Hash representation of the given *big.Int func NewHashFromBigInt(b *big.Int) *Hash { r := &Hash{} copy(r[:], common.SwapEndianness(b.Bytes())) return r } +// MerkleTree is the struct with the main elements of the MerkleTree type MerkleTree struct { sync.RWMutex db db.Storage@@ -74,6 +79,7 @@ writable bool
maxLevels int } +// NewMerkleTree loads a new Merkletree. If in the sotrage already exists one will open that one, if not, will create a new one. func NewMerkleTree(storage db.Storage, maxLevels int) (*MerkleTree, error) { mt := MerkleTree{db: storage, maxLevels: maxLevels, writable: true}@@ -96,10 +102,12 @@ copy(mt.rootKey[:], v)
return &mt, nil } +// Root returns the MerkleRoot func (mt *MerkleTree) Root() *Hash { return mt.rootKey } +// Add adds a Key & Value into the MerkleTree. Where the `k` determines the path from the Root to the Leaf. func (mt *MerkleTree) Add(k, v *big.Int) error { // verify that the MerkleTree is writable if !mt.writable {
M
utils.go
→
utils.go
@@ -52,6 +52,7 @@ }
return NewHashFromBigInt(poseidonHash), nil } +// BigIntsToPoseidonInput takes *big.Ints and returns a fixed-length array of the size `poseidon.T` func BigIntsToPoseidonInput(bigints ...*big.Int) ([poseidon.T]*big.Int, error) { z := big.NewInt(0) b := [poseidon.T]*big.Int{z, z, z, z, z, z}