Sol-merkle-tree-go – 索尔·梅克尔树去区块链毕设代写
区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Sol-merkle-tree-go – 索尔·梅克尔树去区块链毕设代写 是一篇很好的国外资料
Sol-merkle-tree-go
This is a simple merkle tree implementation in go for use within solidity. This was specifically written for use with Uniswaps merkle-distributor.
Usage
import ( "encoding/binary" "fmt" "math/big" solsha3 "github.com/miguelmota/go-solidity-sha3" "github.com/ethereum/go-ethereum/common" "github.com/0xKiwi/sol-merkle-tree-go" ) type User struct { index uint64 account common.Address amount *big.Int } type ClaimInfo struct { Index uint64 Amount string Proof []string } func createDistributionTree(holderArray []*tokenHolder) (map[string]ClaimInfo, error) { // Put per-user proof data into an array of structs. elements := make([]*User, len(holderArray)) for i, holder := range holderArray { elements[i] = &User{ index: uint64(i), account: holder.addr, amount: holder.balance, } } // Solidity hash the data to use as tree leaves. nodes := make([][]byte, len(elements)) for i, user := range elements { hash := solsha3.SoliditySHA3( // Types. []string{"uint256", "address", "uint256"}, // Values. []interface{}{ fmt.Sprintf("%d", user.index), user.account.String(), user.amount.String(), }, ) nodes[i] = hash } // Create the tree. tree, err := solmerkle.GenerateTreeFromItems(nodes) if err != nil { return nil, fmt.Errorf("could not generate trie: %v", err) } distributionRoot := tree.Root() // Map claim data to user address, with the merkle proof for claiming from MerkleDistributor. addrToProof := make(map[string]ClaimInfo, len(holderArray)) for i, holder := range holderArray { proof, err := tree.MerkleProof(nodes[i]) if err != nil { return nil, fmt.Errorf("could not generate proof: %v", err) } addrToProof[holder.addr.String()] = ClaimInfo{ Index: uint64(i), Amount: holder.balance.String(), Proof: stringArrayFrom2DBytes(proof), } } return addrToProof }
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
You can always update your selection by clicking Cookie Preferences at the bottom of the page. For more information, see our Privacy Statement.
Essential cookies
We use essential cookies to perform essential website functions, e.g. they’re used to log you in. Learn more
Always active
Analytics cookies
We use analytics cookies to understand how you use our websites so we can make them better, e.g. they’re used to gather information about the pages you visit and how many clicks you need to accomplish a task. Learn more
Sol-merkle-tree-go
This is a simple merkle tree implementation in go for use within solidity. This was specifically written for use with Uniswaps merkle-distributor.
Usage
import ( "encoding/binary" "fmt" "math/big" solsha3 "github.com/miguelmota/go-solidity-sha3" "github.com/ethereum/go-ethereum/common" "github.com/0xKiwi/sol-merkle-tree-go" ) type User struct { index uint64 account common.Address amount *big.Int } type ClaimInfo struct { Index uint64 Amount string Proof []string } func createDistributionTree(holderArray []*tokenHolder) (map[string]ClaimInfo, error) { // Put per-user proof data into an array of structs. elements := make([]*User, len(holderArray)) for i, holder := range holderArray { elements[i] = &User{ index: uint64(i), account: holder.addr, amount: holder.balance, } } // Solidity hash the data to use as tree leaves. nodes := make([][]byte, len(elements)) for i, user := range elements { hash := solsha3.SoliditySHA3( // Types. []string{"uint256", "address", "uint256"}, // Values. []interface{}{ fmt.Sprintf("%d", user.index), user.account.String(), user.amount.String(), }, ) nodes[i] = hash } // Create the tree. tree, err := solmerkle.GenerateTreeFromItems(nodes) if err != nil { return nil, fmt.Errorf("could not generate trie: %v", err) } distributionRoot := tree.Root() // Map claim data to user address, with the merkle proof for claiming from MerkleDistributor. addrToProof := make(map[string]ClaimInfo, len(holderArray)) for i, holder := range holderArray { proof, err := tree.MerkleProof(nodes[i]) if err != nil { return nil, fmt.Errorf("could not generate proof: %v", err) } addrToProof[holder.addr.String()] = ClaimInfo{ Index: uint64(i), Amount: holder.balance.String(), Proof: stringArrayFrom2DBytes(proof), } } return addrToProof }
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
You can always update your selection by clicking Cookie Preferences at the bottom of the page. For more information, see our Privacy Statement.
Essential cookies
We use essential cookies to perform essential website functions, e.g. they’re used to log you in. Learn more
Always active
Analytics cookies
We use analytics cookies to understand how you use our websites so we can make them better, e.g. they’re used to gather information about the pages you visit and how many clicks you need to accomplish a task. Learn more
部分转自网络,侵权联系删除区块链源码网
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Sol-merkle-tree-go – 索尔·梅克尔树去区块链毕设代写