bank

package
v0.0.0-...-581f9f3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package bank is mainly used to transfer coins between accounts,query account balances, and implement interface rpc.Bank

In addition, the available units of tokens in the irita system are defined using [coin-type](https://www.irisnet.org/docs/concepts/coin-type.html).

[More Details](https://www.irisnet.org/docs/features/bank.html)

As a quick start:

Transfer coins to other account

 client := test.NewClient()
 amt := types.NewIntWithDecimal(1, 18)
 coins := types.NewCoins(types.NewCoin("point", amt))
 to := "faa1hp29kuh22vpjjlnctmyml5s75evsnsd8r4x0mm"
 baseTx := types.BaseTx{
		From: "test1",
		Gas:  20000,
		Memo: "test",
		Mode: types.Commit,
 }
 result,err := client.Bank.Send(to,coins,baseTx)
 fmt.Println(result)

Burn some coins from your account

 client := test.NewClient()
 amt := types.NewIntWithDecimal(1, 18)
 coins := types.NewCoins(types.NewCoin("point", amt))
 baseTx := types.BaseTx{
		From: "test1",
		Gas:  20000,
		Memo: "test",
		Mode: types.Commit,
 }
 result,err := client.Bank.Burn(coins, baseTx)
 fmt.Println(result)

Set account memo

client := test.NewClient()
result,err := client.Bank.SetMemoRegexp("testMemo", baseTx)
fmt.Println(result)

Queries account information

client := test.NewClient()
result,err := client.Bank.QueryAccount("faa1hp29kuh22vpjjlnctmyml5s75evsnsd8r4x0mm")
fmt.Println(result)

Queries the token information

client := test.NewClient()
result,err := client.Bank.QueryTokenStats("point")
fmt.Println(result)

Index

Constants

View Source
const (
	ModuleName = "bank"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account interface {
	GetAddress() sdk.AccAddress
	SetAddress(sdk.AccAddress) error // errors if already set.

	GetPubKey() crypto.PubKey // can return nil.
	SetPubKey(crypto.PubKey) error

	GetAccountNumber() uint64
	SetAccountNumber(uint64) error

	GetSequence() uint64
	SetSequence(uint64) error

	GetCoins() sdk.Coins
	SetCoins(sdk.Coins) error
}

Account is an interface used to store coins at a given address within state. It presumes a notion of sequence numbers for replay protection, a notion of account numbers for replay protection for previously pruned accounts, and a pubkey for authentication purposes.

Many complex conditions can be used in the concrete struct which implements Account.

type Bank

type Bank interface {
	QueryAccount(address string) (sdk.BaseAccount, sdk.Error)
	Send(to string, amount sdk.DecCoins, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error)
	MultiSend(receipts Receipts, baseTx sdk.BaseTx) ([]sdk.ResultTx, sdk.Error)
	Burn(amount sdk.DecCoins, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error)
	SubscribeSendTx(from, to string, callback EventMsgSendCallback) sdk.Subscription
}

expose bank module api for user

func NewClient

func NewClient(bc sdk.BaseClient) Bank

type BaseAccount

type BaseAccount struct {
	Address       sdk.AccAddress `json:"address"`
	Coins         sdk.Coins      `json:"coins"` // will be removed next version
	PubKey        []byte         `json:"public_key"`
	AccountNumber uint64         `json:"account_number"`
	Sequence      uint64         `json:"sequence"`
}

func (*BaseAccount) Convert

func (acc *BaseAccount) Convert() interface{}

func (*BaseAccount) GetAccountNumber

func (acc *BaseAccount) GetAccountNumber() uint64

Implements Account

func (BaseAccount) GetAddress

func (acc BaseAccount) GetAddress() sdk.AccAddress

Implements sdk.Account.

func (*BaseAccount) GetCoins

func (acc *BaseAccount) GetCoins() sdk.Coins

GetCoins - Implements sdk.Account.

func (BaseAccount) GetPubKey

func (acc BaseAccount) GetPubKey() (pk crypto.PubKey)

GetPubKey - Implements sdk.Account.

func (*BaseAccount) GetSequence

func (acc *BaseAccount) GetSequence() uint64

Implements sdk.Account.

func (BaseAccount) MarshalJSON

func (acc BaseAccount) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of a BaseAccount.

func (*BaseAccount) SetAccountNumber

func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error

Implements Account

func (*BaseAccount) SetAddress

func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error

Implements sdk.Account.

func (*BaseAccount) SetCoins

func (acc *BaseAccount) SetCoins(coins sdk.Coins) error

SetCoins - Implements sdk.Account.

func (*BaseAccount) SetPubKey

func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error

SetPubKey - Implements sdk.Account.

func (*BaseAccount) SetSequence

func (acc *BaseAccount) SetSequence(seq uint64) error

Implements sdk.Account.

func (*BaseAccount) UnmarshalJSON

func (acc *BaseAccount) UnmarshalJSON(bz []byte) error

UnmarshalJSON unmarshals raw JSON bytes into a BaseAccount.

type EventDataMsgSend

type EventDataMsgSend struct {
	Height int64      `json:"height"`
	Hash   string     `json:"hash"`
	From   string     `json:"from"`
	To     string     `json:"to"`
	Amount []sdk.Coin `json:"amount"`
}

type EventMsgSendCallback

type EventMsgSendCallback func(EventDataMsgSend)

type Input

type Input struct {
	Address sdk.AccAddress `json:"address"`
	Coins   sdk.Coins      `json:"coins"`
}

Transaction Input

func NewInput

func NewInput(addr sdk.AccAddress, coins sdk.Coins) Input

NewInput - create a transaction input, used with MsgSend

func (Input) ValidateBasic

func (in Input) ValidateBasic() error

ValidateBasic - validate transaction input

type MsgBurn

type MsgBurn struct {
	Owner sdk.AccAddress `json:"owner"`
	Coins sdk.Coins      `json:"coins"`
}

MsgBurn - high level transaction of the coin module

func NewMsgBurn

func NewMsgBurn(owner sdk.AccAddress, coins sdk.Coins) MsgBurn

NewMsgBurn - construct MsgBurn

func (MsgBurn) GetSignBytes

func (msg MsgBurn) GetSignBytes() []byte

Implements Msg.

func (MsgBurn) GetSigners

func (msg MsgBurn) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgBurn) Route

func (msg MsgBurn) Route() string

Implements Msg. nolint

func (MsgBurn) Type

func (msg MsgBurn) Type() string

func (MsgBurn) ValidateBasic

func (msg MsgBurn) ValidateBasic() error

Implements Msg.

type MsgMultiSend

type MsgMultiSend struct {
	Inputs  []Input  `json:"inputs"`
	Outputs []Output `json:"outputs"`
}

func NewMsgMultiSend

func NewMsgMultiSend(in []Input, out []Output) MsgMultiSend

NewMsgSend - construct arbitrary multi-in, multi-out send msg.

func (MsgMultiSend) GetSignBytes

func (msg MsgMultiSend) GetSignBytes() []byte

Implements Msg.

func (MsgMultiSend) GetSigners

func (msg MsgMultiSend) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgMultiSend) Route

func (msg MsgMultiSend) Route() string

func (MsgMultiSend) Type

func (msg MsgMultiSend) Type() string

Implements Msg.

func (MsgMultiSend) ValidateBasic

func (msg MsgMultiSend) ValidateBasic() error

Implements Msg.

type MsgSend

type MsgSend struct {
	FromAddress sdk.AccAddress `json:"from_address"`
	ToAddress   sdk.AccAddress `json:"to_address"`
	Amount      sdk.Coins      `json:"amount"`
}

func NewMsgSend

func NewMsgSend(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) MsgSend

NewMsgSend - construct arbitrary multi-in, multi-out send msg.

func (MsgSend) GetSignBytes

func (msg MsgSend) GetSignBytes() []byte

func (MsgSend) GetSigners

func (msg MsgSend) GetSigners() []sdk.AccAddress

func (MsgSend) Route

func (msg MsgSend) Route() string

func (MsgSend) Type

func (msg MsgSend) Type() string

func (MsgSend) ValidateBasic

func (msg MsgSend) ValidateBasic() error

type Output

type Output struct {
	Address sdk.AccAddress `json:"address"`
	Coins   sdk.Coins      `json:"coins"`
}

Transaction Output

func NewOutput

func NewOutput(addr sdk.AccAddress, coins sdk.Coins) Output

NewOutput - create a transaction output, used with MsgSend

func (Output) ValidateBasic

func (out Output) ValidateBasic() error

ValidateBasic - validate transaction output

type Receipt

type Receipt struct {
	Address string       `json:"address"`
	Amount  sdk.DecCoins `json:"amount"`
}

type Receipts

type Receipts []Receipt

func (Receipts) Len

func (r Receipts) Len() int

func (Receipts) Sub

func (r Receipts) Sub(begin, end int) sdk.SplitAble

Jump to

Keyboard shortcuts

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