Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAccountManipulated = fmt.Errorf("the received account info has been manipulated")
ErrAccountManipulated is used when it seems like an account has been manipulated. This probably means someone is trying to steal funds.
var ErrAccountNotFound = fmt.Errorf("account has not yet been opened")
ErrAccountNotFound is used when an account could not be found by the queried node.
var ErrSignatureMissing = fmt.Errorf("signature is missing")
ErrSignatureMissing is used when the Signature of a Block is missing but required for the attempted operation.
var ErrWorkMissing = fmt.Errorf("work is missing")
ErrWorkMissing is used when the Work of a Block is missing but required for the attempted operation.
var RequestInterceptor func(request *http.Request) error
The RequestInterceptor is a function that is used to modify all HTTP requests that are sent to a node. If it is nil, requests are not modified.
May be used, for example, to authenticate requests.
Functions ¶
Types ¶
type Account ¶
Account holds the public key and address of a Nano account.
func NewAccount ¶
NewAccount creates a new Account and populates both its fields.
func NewAccountFromAddress ¶
NewAccountFromAddress creates a new Account and populates both its fields.
func (Account) FetchAccountInfo ¶
func (a Account) FetchAccountInfo(node string) (i AccountInfo, err error)
FetchAccountInfo fetches the AccountInfo of Account from the given node.
It is also verified, that the retreived AccountInfo is valid by doing a block_info RPC for the frontier, verifying the signature and ensuring that no fields have been changed in the account_info response.
May return ErrAccountNotFound or ErrAccountManipulated.
If ErrAccountNotFound is returned, FirstReceive can be used to create a first Block and AccountInfo and create the account by then submitting this Block.
func (Account) FetchReceivable ¶ added in v1.6.0
func (a Account) FetchReceivable(node string) ([]Receivable, error)
FetchReceivable fetches all unreceived blocks of Account from node.
func (Account) FirstReceive ¶ added in v1.4.0
func (a Account) FirstReceive(receivable Receivable, representative string) (AccountInfo, Block, error)
FirstReceive creates the first receive block of an account. The block will still be missing its signature and work. FirstReceive will also return AccountInfo, which can be used to create further blocks.
type AccountInfo ¶
type AccountInfo struct { // Ignore this field. It only exists because of // https://github.com/nanocurrency/nano-node/issues/1782. Error string `json:"error"` Frontier string `json:"frontier"` Representative string `json:"representative"` Balance string `json:"balance"` PublicKey *big.Int `json:"-"` Address string `json:"-"` }
AccountInfo holds the basic data needed for Block creation.
func (*AccountInfo) Change ¶
func (i *AccountInfo) Change(representative string) (Block, error)
Change creates a change block, which will still be missing its signature and work. The Frontier and Representative of the AccountInfo will be updated.
func (*AccountInfo) Receive ¶
func (i *AccountInfo) Receive(receivable Receivable) (Block, error)
Receive creates a receive block, which will still be missing its signature and work. The Frontier and Balance of the AccountInfo will be updated.
type Block ¶
type Block struct { Type string `json:"type"` Account string `json:"account"` Previous string `json:"previous"` Representative string `json:"representative"` Balance string `json:"balance"` Link string `json:"link"` Signature string `json:"signature"` Work string `json:"work"` // This field is not part of the JSON but needed to improve the // performance of FetchWork and the security of Submit. SubType BlockSubType `json:"-"` }
Block represents a block in the block chain of an account.
func (*Block) FetchWork ¶
FetchWork uses the generate_work RPC on node to fetch and then set the Work of b.
func (*Block) GenerateWork ¶ added in v1.6.0
GenerateWork uses the CPU of the local computer to generate work and then sets it as b.Work.
type BlockSubType ¶
type BlockSubType int64
BlockSubType represents the sub-type of a block.
const ( // SubTypeReceive denotes blocks which raise the balance. SubTypeReceive BlockSubType = iota // SubTypeChange denotes blocks which change the representative. SubTypeChange // SubTypeSend denotes blocks which lower the balance. SubTypeSend )
type Receivable ¶ added in v1.6.0
Receivable represents a block that is waiting to be received.