distributor

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 9 Imported by: 0

README

merkle-distributor

This package is the Go equivalent of github.com/Uniswap/merkle-distributor.

Install

go get -u github.com/fachebot/merkle-distributor

Getting started

Simple example:

package main

import (
	"encoding/json"
	"fmt"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	distributor "github.com/fachebot/merkle-distributor"
)

func main() {
	balances := []distributor.Balance{
		{Account: common.HexToAddress("0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff"), Amount: big.NewInt(200)},
		{Account: common.HexToAddress("0x63FC2aD3d021a4D7e64323529a55a9442C444dA0"), Amount: big.NewInt(300)},
		{Account: common.HexToAddress("0xD1D84F0e28D6fedF03c73151f98dF95139700aa7"), Amount: big.NewInt(250)},
	}
	info, err := distributor.ParseBalanceMap(balances)
	if err != nil {
		panic(err)
	}

	data, err := json.Marshal(info)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(data))
}

Output:

{
	"merkleRoot": "0x2ec9c2fc2a55df417ba88ecd833f165fa3c5941772ebaf8c5f4debe33f4d1b12",
	"tokenTotal": "0x2ee",
	"claims": [{
		"index": 0,
		"amount": "0xc8",
		"proof": ["0x2a411ed78501edb696adca9e41e78d8256b61cfac45612fa0434d7cf87d916c6"]
	}, {
		"index": 1,
		"amount": "0x12c",
		"proof": ["0xbfeb956a3b705056020a3b64c540bff700c0f6c96c55c0a5fcab57124cb36f7b", "0xd31de46890d4a77baeebddbd77bf73b5c626397b73ee8c69b51efe4c9a5a72fa"]
	}, {
		"index": 2,
		"amount": "0xfa",
		"proof": ["0xceaacce7533111e902cc548e961d77b23a4d8cd073c6b68ccf55c62bd47fc36b", "0xd31de46890d4a77baeebddbd77bf73b5c626397b73ee8c69b51efe4c9a5a72fa"]
	}]
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToNode

func ToNode(index int, account common.Address, amount *big.Int) common.Hash

func VerifyProof

func VerifyProof(index int, account common.Address, amount *big.Int, proof Elements, root common.Hash) bool

Types

type Balance

type Balance struct {
	Account common.Address
	Amount  *big.Int
}

type BalanceTree

type BalanceTree struct {
	// contains filtered or unexported fields
}

func NewBalanceTree

func NewBalanceTree(balances []Balance) (*BalanceTree, error)

func (*BalanceTree) GetProof

func (b *BalanceTree) GetProof(index int, account common.Address, amount *big.Int) ([]common.Hash, error)

func (*BalanceTree) GetRoot

func (b *BalanceTree) GetRoot() common.Hash

type Claim

type Claim struct {
	Index  int           `json:"index"`
	Amount string        `json:"amount"`
	Proof  []common.Hash `json:"proof"`
}

type Elements

type Elements []common.Hash

func (Elements) Dedup

func (x Elements) Dedup() Elements

func (Elements) Len

func (x Elements) Len() int

func (Elements) Less

func (x Elements) Less(i, j int) bool

func (Elements) Swap

func (x Elements) Swap(i, j int)

func (Elements) ToHexArray

func (x Elements) ToHexArray() []string

type MerkleDistributorInfo

type MerkleDistributorInfo struct {
	MerkleRoot common.Hash `json:"merkleRoot"`
	TokenTotal string      `json:"tokenTotal"`
	Claims     []Claim     `json:"claims"`
}

func ParseBalanceMap

func ParseBalanceMap(balances []Balance) (MerkleDistributorInfo, error)

type MerkleTree

type MerkleTree struct {
	// contains filtered or unexported fields
}

func NewMerkleTree

func NewMerkleTree(elements Elements) (*MerkleTree, error)

func (*MerkleTree) GetLayers

func (m *MerkleTree) GetLayers(elements Elements) ([][]common.Hash, error)

func (*MerkleTree) GetNextLayer

func (m *MerkleTree) GetNextLayer(elements Elements) Elements

func (*MerkleTree) GetProof

func (m *MerkleTree) GetProof(el common.Hash) ([]common.Hash, error)

func (*MerkleTree) GetRoot

func (m *MerkleTree) GetRoot() common.Hash

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL