2015-07-07 00:54:22 +00:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +00:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 00:54:22 +00:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 16:48:40 +00:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 00:54:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2015-03-16 10:27:38 +00:00
|
|
|
package common
|
|
|
|
|
2015-04-26 22:49:49 +00:00
|
|
|
import (
|
2019-11-15 22:48:49 +00:00
|
|
|
"bytes"
|
2017-03-02 13:03:20 +00:00
|
|
|
"encoding/hex"
|
2018-04-18 10:27:20 +00:00
|
|
|
"encoding/json"
|
2019-11-21 14:34:28 +00:00
|
|
|
"errors"
|
2015-06-15 10:16:29 +00:00
|
|
|
"fmt"
|
2023-10-21 23:17:18 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
2015-04-26 22:49:49 +00:00
|
|
|
"reflect"
|
2018-04-18 10:27:20 +00:00
|
|
|
"strings"
|
2016-11-27 23:58:22 +00:00
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common/length"
|
2015-04-26 22:49:49 +00:00
|
|
|
)
|
2015-03-16 16:09:08 +00:00
|
|
|
|
2018-06-14 09:52:50 +00:00
|
|
|
// Lengths of hashes and addresses in bytes.
|
2015-03-16 17:42:18 +00:00
|
|
|
const (
|
2019-12-06 09:02:43 +00:00
|
|
|
// BlockNumberLength length of uint64 big endian
|
|
|
|
BlockNumberLength = 8
|
2020-01-15 14:55:43 +00:00
|
|
|
// IncarnationLength length of uint64 for contract incarnations
|
|
|
|
IncarnationLength = 8
|
2017-06-23 08:50:49 +00:00
|
|
|
)
|
|
|
|
|
2017-03-02 13:03:20 +00:00
|
|
|
// UnprefixedHash allows marshaling a Hash without 0x prefix.
|
2023-01-13 18:12:18 +00:00
|
|
|
type UnprefixedHash libcommon.Hash
|
2017-03-02 13:03:20 +00:00
|
|
|
|
|
|
|
// UnmarshalText decodes the hash from hex. The 0x prefix is optional.
|
|
|
|
func (h *UnprefixedHash) UnmarshalText(input []byte) error {
|
|
|
|
return hexutil.UnmarshalFixedUnprefixedText("UnprefixedHash", input, h[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalText encodes the hash as hex.
|
|
|
|
func (h UnprefixedHash) MarshalText() ([]byte, error) {
|
|
|
|
return []byte(hex.EncodeToString(h[:])), nil
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:42:18 +00:00
|
|
|
/////////// Address
|
2017-03-02 13:03:20 +00:00
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
var addressT = reflect.TypeOf(libcommon.Address{})
|
2018-07-24 13:15:07 +00:00
|
|
|
|
2018-05-29 10:42:21 +00:00
|
|
|
// UnprefixedAddress allows marshaling an Address without 0x prefix.
|
2023-01-13 18:12:18 +00:00
|
|
|
type UnprefixedAddress libcommon.Address
|
2017-03-02 13:03:20 +00:00
|
|
|
|
|
|
|
// UnmarshalText decodes the address from hex. The 0x prefix is optional.
|
|
|
|
func (a *UnprefixedAddress) UnmarshalText(input []byte) error {
|
|
|
|
return hexutil.UnmarshalFixedUnprefixedText("UnprefixedAddress", input, a[:])
|
|
|
|
}
|
2015-06-15 10:16:29 +00:00
|
|
|
|
2017-03-02 13:03:20 +00:00
|
|
|
// MarshalText encodes the address as hex.
|
|
|
|
func (a UnprefixedAddress) MarshalText() ([]byte, error) {
|
|
|
|
return []byte(hex.EncodeToString(a[:])), nil
|
2015-06-15 10:16:29 +00:00
|
|
|
}
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
|
|
|
|
// MixedcaseAddress retains the original string, which may or may not be
|
|
|
|
// correctly checksummed
|
|
|
|
type MixedcaseAddress struct {
|
2023-01-13 18:12:18 +00:00
|
|
|
addr libcommon.Address
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
original string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMixedcaseAddress constructor (mainly for testing)
|
2023-01-13 18:12:18 +00:00
|
|
|
func NewMixedcaseAddress(addr libcommon.Address) MixedcaseAddress {
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
return MixedcaseAddress{addr: addr, original: addr.Hex()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMixedcaseAddressFromString is mainly meant for unit-testing
|
|
|
|
func NewMixedcaseAddressFromString(hexaddr string) (*MixedcaseAddress, error) {
|
2023-01-13 18:12:18 +00:00
|
|
|
if !libcommon.IsHexAddress(hexaddr) {
|
2019-11-21 14:34:28 +00:00
|
|
|
return nil, errors.New("invalid address")
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
}
|
|
|
|
a := FromHex(hexaddr)
|
2023-01-13 18:12:18 +00:00
|
|
|
return &MixedcaseAddress{addr: libcommon.BytesToAddress(a), original: hexaddr}, nil
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON parses MixedcaseAddress
|
|
|
|
func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error {
|
2023-01-13 18:12:18 +00:00
|
|
|
if err := hexutility.UnmarshalFixedJSON(addressT, input, ma.addr[:]); err != nil {
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return json.Unmarshal(input, &ma.original)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON marshals the original value
|
|
|
|
func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error) {
|
|
|
|
if strings.HasPrefix(ma.original, "0x") || strings.HasPrefix(ma.original, "0X") {
|
|
|
|
return json.Marshal(fmt.Sprintf("0x%s", ma.original[2:]))
|
|
|
|
}
|
|
|
|
return json.Marshal(fmt.Sprintf("0x%s", ma.original))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Address returns the address
|
2023-01-13 18:12:18 +00:00
|
|
|
func (ma *MixedcaseAddress) Address() libcommon.Address {
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 12:04:32 +00:00
|
|
|
return ma.addr
|
|
|
|
}
|
|
|
|
|
|
|
|
// String implements fmt.Stringer
|
|
|
|
func (ma *MixedcaseAddress) String() string {
|
|
|
|
if ma.ValidChecksum() {
|
|
|
|
return fmt.Sprintf("%s [chksum ok]", ma.original)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s [chksum INVALID]", ma.original)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidChecksum returns true if the address has valid checksum
|
|
|
|
func (ma *MixedcaseAddress) ValidChecksum() bool {
|
|
|
|
return ma.original == ma.addr.Hex()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Original returns the mixed-case input string
|
|
|
|
func (ma *MixedcaseAddress) Original() string {
|
|
|
|
return ma.original
|
|
|
|
}
|
2019-11-15 22:48:49 +00:00
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
// Addresses is a slice of libcommon.Address, implementing sort.Interface
|
|
|
|
type Addresses []libcommon.Address
|
2021-05-10 15:07:22 +00:00
|
|
|
|
|
|
|
func (addrs Addresses) Len() int {
|
|
|
|
return len(addrs)
|
|
|
|
}
|
|
|
|
func (addrs Addresses) Less(i, j int) bool {
|
|
|
|
return bytes.Compare(addrs[i][:], addrs[j][:]) == -1
|
|
|
|
}
|
|
|
|
func (addrs Addresses) Swap(i, j int) {
|
|
|
|
addrs[i], addrs[j] = addrs[j], addrs[i]
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
// Hashes is a slice of libcommon.Hash, implementing sort.Interface
|
|
|
|
type Hashes []libcommon.Hash
|
2019-11-15 22:48:49 +00:00
|
|
|
|
|
|
|
func (hashes Hashes) Len() int {
|
|
|
|
return len(hashes)
|
|
|
|
}
|
|
|
|
func (hashes Hashes) Less(i, j int) bool {
|
|
|
|
return bytes.Compare(hashes[i][:], hashes[j][:]) == -1
|
|
|
|
}
|
|
|
|
func (hashes Hashes) Swap(i, j int) {
|
|
|
|
hashes[i], hashes[j] = hashes[j], hashes[i]
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
const StorageKeyLen = 2*length.Hash + IncarnationLength
|
2020-10-02 03:56:13 +00:00
|
|
|
|
2019-11-15 22:48:49 +00:00
|
|
|
// StorageKey is representation of address of a contract storage item
|
|
|
|
// It consists of two parts, each of which are 32-byte hashes:
|
|
|
|
// 1. Hash of the contract's address
|
|
|
|
// 2. Hash of the item's key
|
2020-10-02 03:56:13 +00:00
|
|
|
type StorageKey [StorageKeyLen]byte
|
2019-11-15 22:48:49 +00:00
|
|
|
|
|
|
|
// StorageKeys is a slice of StorageKey, implementing sort.Interface
|
|
|
|
type StorageKeys []StorageKey
|
|
|
|
|
|
|
|
func (keys StorageKeys) Len() int {
|
|
|
|
return len(keys)
|
|
|
|
}
|
|
|
|
func (keys StorageKeys) Less(i, j int) bool {
|
|
|
|
return bytes.Compare(keys[i][:], keys[j][:]) == -1
|
|
|
|
}
|
|
|
|
func (keys StorageKeys) Swap(i, j int) {
|
|
|
|
keys[i], keys[j] = keys[j], keys[i]
|
|
|
|
}
|