Documentation ¶
Index ¶
- Constants
- func H4ToString(h4 []uint64) string
- func KeyCodeLength(ethAddr common.Address) ([]byte, error)
- func KeyContractCode(ethAddr common.Address) ([]byte, error)
- func KeyContractStorage(ethAddr common.Address, storagePos []byte) ([]byte, error)
- func KeyEthAddrBalance(ethAddr common.Address) ([]byte, error)
- func KeyEthAddrNonce(ethAddr common.Address) ([]byte, error)
- func NewMTDBServiceClient(ctx context.Context, c Config) (pb.HashDBServiceClient, *grpc.ClientConn, context.CancelFunc)
- func ScalarToFilledByteSlice(s *big.Int) []byte
- func StringToh4(str string) ([]uint64, error)
- type Config
- type Key
- type ProgramProof
- type Proof
- type ResultCode
- type StateTree
- func (tree *StateTree) Flush(ctx context.Context) error
- func (tree *StateTree) GetBalance(ctx context.Context, address common.Address, root []byte) (*big.Int, error)
- func (tree *StateTree) GetCode(ctx context.Context, address common.Address, root []byte) ([]byte, error)
- func (tree *StateTree) GetCodeHash(ctx context.Context, address common.Address, root []byte) ([]byte, error)
- func (tree *StateTree) GetNonce(ctx context.Context, address common.Address, root []byte) (*big.Int, error)
- func (tree *StateTree) GetStorageAt(ctx context.Context, address common.Address, position *big.Int, root []byte) (*big.Int, error)
- func (tree *StateTree) SetBalance(ctx context.Context, address common.Address, balance *big.Int, root []byte) (newRoot []byte, proof *UpdateProof, err error)
- func (tree *StateTree) SetCode(ctx context.Context, address common.Address, code []byte, root []byte) (newRoot []byte, proof *UpdateProof, err error)
- func (tree *StateTree) SetNonce(ctx context.Context, address common.Address, nonce *big.Int, root []byte) (newRoot []byte, proof *UpdateProof, err error)
- func (tree *StateTree) SetStorageAt(ctx context.Context, address common.Address, position *big.Int, value *big.Int, ...) (newRoot []byte, proof *UpdateProof, err error)
- type UpdateProof
Constants ¶
const ( // LeafTypeBalance specifies that leaf stores Balance LeafTypeBalance leafType = 0 // LeafTypeNonce specifies that leaf stores Nonce LeafTypeNonce leafType = 1 // LeafTypeCode specifies that leaf stores Code LeafTypeCode leafType = 2 // LeafTypeStorage specifies that leaf stores Storage Value LeafTypeStorage leafType = 3 // LeafTypeSCLength specifies that leaf stores Storage Value LeafTypeSCLength leafType = 4 )
const ( // HashPoseidonAllZeroes represents the poseidon hash for an input with all // bits set to zero. HashPoseidonAllZeroes = "0xc71603f33a1144ca7953db0ab48808f4c4055e3364a246c33c18a9786cb0b359" )
Variables ¶
This section is empty.
Functions ¶
func H4ToString ¶
H4ToString converts array of 4 Scalars of 64 bits into an hex string.
func KeyCodeLength ¶
KeyCodeLength returns the key of code length leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 4, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]
func KeyContractCode ¶
KeyContractCode returns the key of contract code leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 2, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]
func KeyContractStorage ¶
KeyContractStorage returns the key of contract storage position leaf: hk0: H([stoPos[0:4], stoPos[4:8], stoPos[8:12], stoPos[12:16], stoPos[16:20], stoPos[20:24], stoPos[24:28], stoPos[28:32], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 3, 0], [hk0[0], hk0[1], hk0[2], hk0[3])
func KeyEthAddrBalance ¶
KeyEthAddrBalance returns the key of balance leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 0, 0], [hk0[0], hk0[1], hk0[2], hk0[3]])
func KeyEthAddrNonce ¶
KeyEthAddrNonce returns the key of nonce leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 1, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]
func NewMTDBServiceClient ¶
func NewMTDBServiceClient(ctx context.Context, c Config) (pb.HashDBServiceClient, *grpc.ClientConn, context.CancelFunc)
NewMTDBServiceClient creates a new MTDB client.
func ScalarToFilledByteSlice ¶
ScalarToFilledByteSlice converts a *big.Int into an array of maxBigIntLen bytes.
func StringToh4 ¶
StringToh4 converts an hex string into array of 4 Scalars of 64 bits.
Types ¶
type Config ¶
type Config struct { // URI is the server URI. URI string `mapstructure:"URI"` }
Config represents the configuration of the merkletree server.
type ProgramProof ¶
type ProgramProof struct { // Data is the program proof data. Data []byte }
ProgramProof is a proof generated on GetProgram operation.
type Proof ¶
type Proof struct { // Root is the proof root. Root []uint64 // Key is the proof key. Key []uint64 // Value is the proof value. Value []uint64 }
Proof is a proof generated on Get operation.
type ResultCode ¶
type ResultCode int64
ResultCode represents the result code.
const ( // Unspecified is the code for unspecified result. Unspecified ResultCode = iota // Success is the code for success result. Success // KeyNotFound is the code for key not found result. KeyNotFound // DBError is the code for DB error result. DBError // InternalError is the code for internal error result. InternalError )
type StateTree ¶
type StateTree struct {
// contains filtered or unexported fields
}
StateTree provides methods to access and modify state in merkletree
func NewStateTree ¶
func NewStateTree(client pb.HashDBServiceClient) *StateTree
NewStateTree creates new StateTree.
func (*StateTree) GetBalance ¶
func (tree *StateTree) GetBalance(ctx context.Context, address common.Address, root []byte) (*big.Int, error)
GetBalance returns balance.
func (*StateTree) GetCode ¶
func (tree *StateTree) GetCode(ctx context.Context, address common.Address, root []byte) ([]byte, error)
GetCode returns code.
func (*StateTree) GetCodeHash ¶
func (tree *StateTree) GetCodeHash(ctx context.Context, address common.Address, root []byte) ([]byte, error)
GetCodeHash returns code hash.
func (*StateTree) GetNonce ¶
func (tree *StateTree) GetNonce(ctx context.Context, address common.Address, root []byte) (*big.Int, error)
GetNonce returns nonce.
func (*StateTree) GetStorageAt ¶
func (tree *StateTree) GetStorageAt(ctx context.Context, address common.Address, position *big.Int, root []byte) (*big.Int, error)
GetStorageAt returns Storage Value at specified position.
func (*StateTree) SetBalance ¶
func (tree *StateTree) SetBalance(ctx context.Context, address common.Address, balance *big.Int, root []byte) (newRoot []byte, proof *UpdateProof, err error)
SetBalance sets balance.
func (*StateTree) SetCode ¶
func (tree *StateTree) SetCode(ctx context.Context, address common.Address, code []byte, root []byte) (newRoot []byte, proof *UpdateProof, err error)
SetCode sets smart contract code.
type UpdateProof ¶
type UpdateProof struct { // OldRoot is the update proof old root. OldRoot []uint64 // NewRoot is the update proof new root. NewRoot []uint64 // Key is the update proof key. Key []uint64 // NewValue is the update proof new value. NewValue []uint64 }
UpdateProof is a proof generated on Set operation.