account

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AddressHexLength = 2 * binary.Word160Length

Variables

View Source
var GlobalPermissionsAddress = Address(binary.Zero160)
View Source
var ZeroAddress = Address{}

Functions

func EnsureEd25519PrivateKeyCorrect added in v0.18.0

func EnsureEd25519PrivateKeyCorrect(candidatePrivateKey ed25519.PrivateKey) error

Ensures the last 32 bytes of the ed25519 private key is the public key derived from the first 32 private bytes

func SignBytes

func SignBytes(chainID string, o Signable) []byte

SignBytes is a convenience method for getting the bytes to sign of a Signable.

Types

type Account

type Account interface {
	Addressable
	// The value held by this account in terms of the chain-native token
	Balance() uint64
	// The EVM byte code held by this account (or equivalently, this contract)
	Code() Bytecode
	// The sequence number of this account, incremented each time a mutation of the
	// Account is persisted to the blockchain state
	Sequence() uint64
	// The hash of all the values in this accounts storage (typically the root of some subtree
	// in the merkle tree of global storage state)
	StorageRoot() []byte
	// The permission flags and roles for this account
	Permissions() ptypes.AccountPermissions
	// Obtain a deterministic serialisation of this account
	// (i.e. update order and Go runtime independent)
	Encode() ([]byte, error)
	// String representation of the account
	String() string
}

The default immutable interface to an account

func AsAccount added in v0.18.0

func AsAccount(account Account) Account

Returns an immutable account by copying from account

func Decode added in v0.18.0

func Decode(accBytes []byte) (Account, error)

type Address added in v0.18.0

type Address binary.Word160

func AddressFromBytes added in v0.18.0

func AddressFromBytes(bs []byte) (address Address, err error)

Returns an address consisting of the first 20 bytes of bs, return an error if the bs does not have length exactly 20 but will still return either: the bytes in bs padded on the right or the first 20 bytes of bs truncated in any case.

func AddressFromHexString added in v0.18.0

func AddressFromHexString(str string) (Address, error)

func AddressFromWord256 added in v0.18.0

func AddressFromWord256(addr binary.Word256) Address

func MaybeAddressFromBytes added in v0.18.0

func MaybeAddressFromBytes(bs []byte) (*Address, error)

Returns a pointer to an Address that is nil iff len(bs) == 0 otherwise does the same as AddressFromBytes

func MustAddressFromBytes added in v0.18.0

func MustAddressFromBytes(addr []byte) Address

func NewContractAddress added in v0.18.0

func NewContractAddress(caller Address, sequence uint64) (newAddr Address)

func (Address) Bytes added in v0.18.0

func (address Address) Bytes() []byte

Copy address and return a slice onto the copy

func (Address) MarshalJSON added in v0.18.0

func (address Address) MarshalJSON() ([]byte, error)

func (Address) MarshalText added in v0.18.0

func (address Address) MarshalText() ([]byte, error)

func (Address) String added in v0.18.0

func (address Address) String() string

func (*Address) UnmarshalJSON added in v0.18.0

func (address *Address) UnmarshalJSON(data []byte) error

func (*Address) UnmarshalText added in v0.18.0

func (address *Address) UnmarshalText(text []byte) error

func (Address) Word256 added in v0.18.0

func (address Address) Word256() binary.Word256

type Addressable added in v0.18.0

type Addressable interface {
	// Get the 20 byte EVM address of this account
	Address() Address
	// Public key from which the Address is derived
	PublicKey() PublicKey
}

type AddressableSigner added in v0.18.0

type AddressableSigner interface {
	Addressable
	Signer
}

func SigningAccounts added in v0.18.0

func SigningAccounts(concretePrivateAccounts []*ConcretePrivateAccount) []AddressableSigner

Convert slice of ConcretePrivateAccounts to slice of SigningAccounts

type Addresses added in v0.18.0

type Addresses []Address

func (Addresses) Len added in v0.18.0

func (as Addresses) Len() int

func (Addresses) Less added in v0.18.0

func (as Addresses) Less(i, j int) bool

func (Addresses) Swap added in v0.18.0

func (as Addresses) Swap(i, j int)

type Bytecode added in v0.18.0

type Bytecode []byte

func BytecodeFromHex added in v0.18.0

func BytecodeFromHex(hexString string) (Bytecode, error)

func NewBytecode added in v0.18.0

func NewBytecode(bytelikes ...interface{}) (Bytecode, error)

Builds new bytecode using the Splice helper to map byte-like and byte-slice-like types to a flat bytecode slice

func (Bytecode) Bytes added in v0.18.0

func (bc Bytecode) Bytes() []byte

func (Bytecode) MarshalJSON added in v0.18.0

func (bc Bytecode) MarshalJSON() ([]byte, error)

func (Bytecode) MarshalText added in v0.18.0

func (bc Bytecode) MarshalText() ([]byte, error)

func (Bytecode) String added in v0.18.0

func (bc Bytecode) String() string

func (Bytecode) Tokens added in v0.18.0

func (bc Bytecode) Tokens() ([]string, error)

Tokenises the bytecode into opcodes and values

func (*Bytecode) UnmarshalJSON added in v0.18.0

func (bc *Bytecode) UnmarshalJSON(data []byte) error

func (*Bytecode) UnmarshalText added in v0.18.0

func (bc *Bytecode) UnmarshalText(text []byte) error

type ConcreteAccount added in v0.18.0

type ConcreteAccount struct {
	Address     Address
	PublicKey   PublicKey
	Sequence    uint64
	Balance     uint64
	Code        Bytecode
	StorageRoot []byte
	Permissions ptypes.AccountPermissions
}

ConcreteAccount is the canonical serialisation and bash-in-place object for an Account

func AsConcreteAccount added in v0.18.0

func AsConcreteAccount(account Account) *ConcreteAccount

Returns a mutable, serialisable ConcreteAccount by copying from account

func DecodeConcrete added in v0.18.0

func DecodeConcrete(accBytes []byte) (*ConcreteAccount, error)

func NewConcreteAccount added in v0.18.0

func NewConcreteAccount(pubKey PublicKey) ConcreteAccount

func NewConcreteAccountFromSecret added in v0.18.0

func NewConcreteAccountFromSecret(secret string) ConcreteAccount

func (ConcreteAccount) Account added in v0.18.0

func (acc ConcreteAccount) Account() Account

Return as immutable Account

func (*ConcreteAccount) Copy added in v0.18.0

func (acc *ConcreteAccount) Copy() *ConcreteAccount

func (*ConcreteAccount) Encode added in v0.18.0

func (acc *ConcreteAccount) Encode() ([]byte, error)

func (ConcreteAccount) MutableAccount added in v0.18.0

func (acc ConcreteAccount) MutableAccount() MutableAccount

Return as mutable MutableAccount

func (*ConcreteAccount) String added in v0.18.0

func (acc *ConcreteAccount) String() string

type ConcretePrivateAccount added in v0.18.0

type ConcretePrivateAccount struct {
	Address    Address
	PublicKey  PublicKey
	PrivateKey PrivateKey
}

func AsConcretePrivateAccount added in v0.18.0

func AsConcretePrivateAccount(privateAccount PrivateAccount) *ConcretePrivateAccount

func (ConcretePrivateAccount) PrivateAccount added in v0.18.0

func (pa ConcretePrivateAccount) PrivateAccount() PrivateAccount

func (ConcretePrivateAccount) Sign added in v0.18.0

func (pa ConcretePrivateAccount) Sign(msg []byte) (Signature, error)

func (*ConcretePrivateAccount) String added in v0.18.0

func (pa *ConcretePrivateAccount) String() string

type ConcreteValidator added in v0.18.0

type ConcreteValidator struct {
	Address   Address
	PublicKey PublicKey
	Power     uint64
}

Neither abci_types or tm_types has quite the representation we want

func AsConcreteValidator added in v0.18.0

func AsConcreteValidator(validator Validator) *ConcreteValidator

func (*ConcreteValidator) Copy added in v0.18.0

func (*ConcreteValidator) String added in v0.18.0

func (cv *ConcreteValidator) String() string

func (ConcreteValidator) Validator added in v0.18.0

func (cv ConcreteValidator) Validator() Validator

type MutableAccount added in v0.18.0

type MutableAccount interface {
	Account
	// Set public key (needed for lazy initialisation), should also set the dependent address
	SetPublicKey(pubKey PublicKey) MutableAccount
	// Subtract amount from account balance (will panic if amount is greater than balance)
	SubtractFromBalance(amount uint64) (MutableAccount, error)
	// Add amount to balance (will panic if amount plus balance is a uint64 overflow)
	AddToBalance(amount uint64) (MutableAccount, error)
	// Set EVM byte code associated with account
	SetCode(code []byte) MutableAccount
	// Increment Sequence number by 1 (capturing the current Sequence number as the index for any pending mutations)
	IncSequence() MutableAccount
	// Set the storage root hash
	SetStorageRoot(storageRoot []byte) MutableAccount
	// Set account permissions
	SetPermissions(permissions ptypes.AccountPermissions) MutableAccount
	// Get a pointer this account's AccountPermissions in order to mutate them
	MutablePermissions() *ptypes.AccountPermissions
	// Create a complete copy of this MutableAccount that is itself mutable
	Copy() MutableAccount
}

func AsMutableAccount added in v0.18.0

func AsMutableAccount(account Account) MutableAccount

Returns a MutableAccount by copying from account

func FromAddressable added in v0.18.0

func FromAddressable(addressable Addressable) MutableAccount

Creates an otherwise zeroed Account from an Addressable and returns it as MutableAccount

type PrivateAccount added in v0.18.0

type PrivateAccount interface {
	AddressableSigner
	PrivateKey() PrivateKey
}

func GeneratePrivateAccount added in v0.18.0

func GeneratePrivateAccount() (PrivateAccount, error)

Generates a new account with private key.

func GeneratePrivateAccountFromPrivateKeyBytes added in v0.18.0

func GeneratePrivateAccountFromPrivateKeyBytes(privKeyBytes []byte) (PrivateAccount, error)

func GeneratePrivateAccountFromSecret added in v0.18.0

func GeneratePrivateAccountFromSecret(secret string) PrivateAccount

Generates a new account with private key from SHA256 hash of a secret

type PrivateKey added in v0.18.0

type PrivateKey struct {
	crypto.PrivKey `json:"unwrap"`
}

func Ed25519PrivateKeyFromRawBytes added in v0.18.0

func Ed25519PrivateKeyFromRawBytes(privKeyBytes []byte) (PrivateKey, error)

Creates an ed25519 key from the raw private key bytes

func GeneratePrivateKey added in v0.18.0

func GeneratePrivateKey(randomReader io.Reader) (PrivateKey, error)

Generates private key from a source of random bytes, if randomReader is nil crypto/rand.Reader is useds

func PrivateKeyFromGoCryptoPrivKey added in v0.18.0

func PrivateKeyFromGoCryptoPrivKey(privKey crypto.PrivKey) (PrivateKey, error)

func PrivateKeyFromSecret added in v0.18.0

func PrivateKeyFromSecret(secret string) PrivateKey

func (PrivateKey) MarshalJSON added in v0.18.0

func (pk PrivateKey) MarshalJSON() ([]byte, error)

func (PrivateKey) MarshalText added in v0.18.0

func (pk PrivateKey) MarshalText() ([]byte, error)

func (PrivateKey) PublicKey added in v0.18.0

func (pk PrivateKey) PublicKey() PublicKey

func (PrivateKey) RawBytes added in v0.18.0

func (pk PrivateKey) RawBytes() []byte

Returns a copy of the raw untyped private key bytes

func (PrivateKey) Sign added in v0.18.0

func (pk PrivateKey) Sign(msg []byte) (Signature, error)

func (*PrivateKey) UnmarshalJSON added in v0.18.0

func (pk *PrivateKey) UnmarshalJSON(data []byte) error

func (*PrivateKey) UnmarshalText added in v0.18.0

func (pk *PrivateKey) UnmarshalText(text []byte) error

type PublicKey added in v0.18.0

type PublicKey struct {
	crypto.PubKey `json:"unwrap"`
}

PublicKey

func PublicKeyFromBytes added in v0.18.0

func PublicKeyFromBytes(bs []byte) (PublicKey, error)

Currently this is a stub that reads the raw bytes returned by key_client and returns an ed25519 public key.

func PublicKeyFromGoCryptoPubKey added in v0.18.0

func PublicKeyFromGoCryptoPubKey(pubKey crypto.PubKey) (PublicKey, error)

func (PublicKey) Address added in v0.18.0

func (pk PublicKey) Address() Address

func (PublicKey) MarshalJSON added in v0.18.0

func (pk PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) MarshalText added in v0.18.0

func (pk PublicKey) MarshalText() ([]byte, error)

func (PublicKey) RawBytes added in v0.18.0

func (pk PublicKey) RawBytes() []byte

Returns a copy of the raw untyped public key bytes

func (*PublicKey) UnmarshalJSON added in v0.18.0

func (pk *PublicKey) UnmarshalJSON(data []byte) error

func (*PublicKey) UnmarshalText added in v0.18.0

func (pk *PublicKey) UnmarshalText(text []byte) error

func (PublicKey) VerifyBytes added in v0.18.0

func (pk PublicKey) VerifyBytes(msg []byte, signature Signature) bool

type Signable

type Signable interface {
	WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
}

Signable is an interface for all signable things. It typically removes signatures before serializing.

type Signature added in v0.18.0

type Signature struct {
	crypto.Signature `json:"unwrap"`
}

func ChainSign added in v0.18.0

func ChainSign(signer Signer, chainID string, o Signable) (Signature, error)

func SignatureFromBytes added in v0.18.0

func SignatureFromBytes(bs []byte) (Signature, error)

Currently this is a stub that reads the raw bytes returned by key_client and returns an ed25519 signature.

func SignatureFromGoCryptoSignature added in v0.18.0

func SignatureFromGoCryptoSignature(signature crypto.Signature) Signature

func (Signature) GoCryptoSignature added in v0.18.0

func (s Signature) GoCryptoSignature() crypto.Signature

func (Signature) MarshalJSON added in v0.18.0

func (s Signature) MarshalJSON() ([]byte, error)

func (Signature) MarshalText added in v0.18.0

func (s Signature) MarshalText() ([]byte, error)

func (*Signature) UnmarshalJSON added in v0.18.0

func (s *Signature) UnmarshalJSON(data []byte) error

func (*Signature) UnmarshalText added in v0.18.0

func (s *Signature) UnmarshalText(text []byte) error

type Signer added in v0.18.0

type Signer interface {
	Sign(msg []byte) (Signature, error)
}

type Validator added in v0.18.0

type Validator interface {
	Addressable
	// The validator's voting power
	Power() uint64
	// Alter the validator's voting power by amount that can be negative or positive.
	// A power of 0 effectively unbonds the validator
	WithNewPower(uint64) Validator
}

func AsValidator added in v0.18.0

func AsValidator(account Account) Validator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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