tron

package module
v0.0.0-...-614c40b Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

tron-proof

This is a merkle-proof package that supports tron transaction proofs.

Installation
go get github.com/arberiii/tron-proof
Usage
client := service.NewGrpcClient("grpc.trongrid.io:50051")
client.Start()

block := client.GetBlockByNum(17318273)
client.Conn.Close()
var hashes [][]byte
for _, tx := range block.Transactions {
    rawData, err := proto.Marshal(tx)
    if err != nil {
        t.Fatal(err)
    }
    h256h := sha256.New()
    h256h.Write(rawData)
    hash := h256h.Sum(nil)

    hashes = append(hashes, hash)
}

m := tron.CreateMerkleTree(hashes)
log.Println(m.Root())

// Generate proof for transaction number 0
proof := m.GenerateProof(0)
if !tron.VerifyProof(hashes[0], m.Root(), proof) {
    t.Errorf("merkle proof of transaction %d is not correct", 0)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyProof

func VerifyProof(elem, root []byte, proof []*node) bool

Types

type MerkleTree

type MerkleTree struct {
	Leaves []*leaf
	Size   int
}

func CreateMerkleTree

func CreateMerkleTree(hashes [][]byte) *MerkleTree

func (*MerkleTree) GenerateProof

func (m *MerkleTree) GenerateProof(i int) []*node

func (*MerkleTree) Root

func (m *MerkleTree) Root() []byte

Jump to

Keyboard shortcuts

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