Documentation
¶
Index ¶
- Constants
- Variables
- func MaxI128() *big.Int
- func MaxU128() *big.Int
- func MaxU256() *big.Int
- func MinI128() *big.Int
- func MinU128() *big.Int
- func MinU256() *big.Int
- func NewRegistry(homeDir string) *registry
- func WithHome(home string) massaClientOptFunc
- func WithMaxRetries(val uint32) apiClientOptFn
- func WithNumAvailable(val uint32) apiClientOptFn
- func WithRetryInterval(val time.Duration) apiClientOptFn
- func WithWalletHome(dir string) walletOptFunc
- type ApiClient
- func (a *ApiClient) GetOperations(opIds ...string) ([]*massapb.OperationWrapper, error)
- func (a *ApiClient) Init(ApiUrls ...string) error
- func (a *ApiClient) NewOperation(from string, opData OperationData) (Operation, error)
- func (a *ApiClient) ReadSC(caller string, callData CallData) ([]byte, error)
- func (a *ApiClient) SendOperation(op Operation) (string, error)
- type Args
- func (a *Args) AddBool(val bool)
- func (a *Args) AddByteSlice(val []byte)
- func (a *Args) AddFloat32(val float64)
- func (a *Args) AddFloat64(val float64)
- func (a *Args) AddInt128(val Int128)
- func (a *Args) AddInt32(val int32)
- func (a *Args) AddInt64(val int64)
- func (a *Args) AddString(val String)
- func (a *Args) AddUint128(val Uint128)
- func (a *Args) AddUint256(val Uint256)
- func (a *Args) AddUint32(val uint32)
- func (a *Args) AddUint64(val uint64)
- func (a *Args) AddUint8(val uint8)
- func (a *Args) NextUint8() (uint8, error)
- type CallData
- type GetProviderRequest
- type IMassaClient
- type Int128
- type Int32
- type Int64
- type MassaAccount
- type MassaClient
- func (c *MassaClient) CallSC(callerAddr, targetAddr, targetFunc string, params []byte, coins uint64) (opId string, err error)
- func (c *MassaClient) ImportFromPriv(privEncoded, password string) (addr string, err error)
- func (c *MassaClient) Init(jsonRpcUrls ...string) error
- func (c *MassaClient) SendTransaction(sender, recipientAddr string, amount uint64) (opId string, err error)
- type MassaSignature
- type Operation
- type OperationData
- type OperationType
- type RegisteredAccount
- type RpcType
- type String
- type TxData
- type Uint128
- type Uint256
- type Uint32
- type Uint64
- type Uint8
- type UnlockedAccount
- type Wallet
- func (s *Wallet) GenerateAccount(accountPassword string) (string, error)
- func (s *Wallet) GetWalletHome() string
- func (s *Wallet) ImportFromFile(filePath, password string) (addr string, err error)
- func (s *Wallet) ImportFromPriv(privEncoded, password string) (addr string, err error)
- func (s *Wallet) Init() error
- func (s *Wallet) KeystoreDir() string
- func (w *Wallet) ListUnlockedAccounts() (addrs []string)
- func (w *Wallet) SignMessage(addr string, msg string) (MassaSignature, error)
- func (w *Wallet) SignOperation(op Operation) (Operation, error)
- func (s *Wallet) UnlockAccount(addr, password string) error
Constants ¶
const ( // Public API ports DEFAULT_GRPC_PORT = "33037" DEFAULT_JSON_RPC_PORT = "33035" DEFAULT_PERIOD_OFFSET uint64 = 5 DEFAULT_READ_ONLY_CALL_FEE uint64 = 0.01 * 1e9 MANTISSA_SCALE uint32 = 9 DEFAULT_TARGET_NUM_GRPC_AVAILABLE uint32 = 3 DEFAULT_GET_PROVIDER_MAX_RETRIES uint32 = 3 DEFAULT_GET_PROVIDER_RETRY_INTERVAL time.Duration = 5 * time.Second DEFAULT_KDF_ITER = 600_000 DEFAULT_KDF_KEY_LEN = 32 SECRET_KEY_PREFIX = "S" PUBLIC_KEY_PREFIX = "P" ADDRESS_USER_PREFIX = "AU" ADDRESS_CONTRACT_PREFIX = "AS" OPERATION_ID_PREFIX = "O" ADDRESS_PREIX_LENGTH uint64 = 2 KEYS_VERSION_NUMBER uint64 = 0 MAX_BLOCK_GAS = 4_294_967_295 DEFAULT_MAINNET_JSON_RPC = "https://mainnet.massa.net/api/v2" )
Variables ¶
var ( ErrWrongMac = errors.New("derived mac does not match expected mac") ErrBadInitialAddrs = errors.New("no available endpoints in initial API addresses") ErrTooManyRetries = errors.New("too many retries on get provider request") ErrInvalidMassaPriv = errors.New("invalid massa private key") ErrInvalidMassaPub = errors.New("invalid massa public key") ErrPrivLength = errors.New("private key has wrong length") ErrReadUvarint = errors.New("failed reading version uvarint") ErrAccountNotFound = errors.New("account not found for address") ErrRegAccountNotFound = errors.New("account not found in registry, please import account") ErrIsDir = errors.New("provide path to file is directory path") )
var (
ErrOutOfRange = errors.New("slice index out of range")
)
Functions ¶
func NewRegistry ¶
func NewRegistry(homeDir string) *registry
func WithMaxRetries ¶
func WithMaxRetries(val uint32) apiClientOptFn
Configuration function that sets the maximum number of retries before a getProvider request will return an error.
func WithNumAvailable ¶
func WithNumAvailable(val uint32) apiClientOptFn
Configuration function to set the target number of gRPC APIs that should be available at any one time. If not enough APIs are accessible then the embedded apiManager will attempt to discover more.
func WithRetryInterval ¶
COnfiguration function that sets the amount of time to wait after a failed getProvider request before trying again.
func WithWalletHome ¶
func WithWalletHome(dir string) walletOptFunc
Types ¶
type ApiClient ¶
type ApiClient struct {
// contains filtered or unexported fields
}
ApiClient embeds an api manager that handles automatic api discovery, api reconnects, and getting api endpoints.
Exports methods for interacting with the blockchain through the JSON-RPC and gRPC APIs.
func NewApiClient ¶
func NewApiClient(optFns ...apiClientOptFn) *ApiClient
Returns a pointer to a new ApiClient, configurable with the provided configuration functions.
func (*ApiClient) GetOperations ¶
func (a *ApiClient) GetOperations(opIds ...string) ([]*massapb.OperationWrapper, error)
Gets the associated operations for the provided ids.
Returns an error if the request was not successful.
func (*ApiClient) Init ¶
Init carries out the following steps: Starts initial endpoint discovery, waits for an available gRPC endpoint, and instantiates public grpc service client.
Returns error on failure to instantiate client
func (*ApiClient) NewOperation ¶
func (a *ApiClient) NewOperation(from string, opData OperationData) (Operation, error)
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
func (*Args) AddByteSlice ¶
func (*Args) AddFloat32 ¶
func (*Args) AddFloat64 ¶
func (*Args) AddUint128 ¶
func (*Args) AddUint256 ¶
type CallData ¶
type CallData struct { Fee uint64 MaxGas uint64 Coins uint64 TargetAddress string TargetFunction string Parameter []byte }
func NewCallData ¶
func (CallData) Type ¶
func (c CallData) Type() OperationType
type GetProviderRequest ¶
type GetProviderRequest struct { RpcType RpcType Retries uint32 ResultCh chan apiProvider ErrorCh chan error }
A request that is used to asynchronously get an ApiProvider from the api manager.
type IMassaClient ¶
type IMassaClient interface { // Wallet functionality GetAccount() GenerateAccount() ImportAccount() LoadAccount() LoadAccountFromPriv() GetWalletHome() SignOperation() SignMessage() // ApiClient functionality NewOperation() SendOperation() GetOperations() ReadSC() // MassaClient Functionality SendTransaction() CallSC() }
Just for keeping track of public methods.
type MassaAccount ¶
type MassaAccount struct {
// contains filtered or unexported fields
}
func GenerateAccount ¶
func GenerateAccount() (MassaAccount, error)
Generates a Massa Account and saves the corresponding keystore file to the default directory. The user will be prompted for a password.
Returns the generated account.
func LoadAccountFromPriv ¶
func LoadAccountFromPriv(privEncoded string) (MassaAccount, error)
Loads the corresponding account and saves the keystore file at the default keystore location (see defaultKeystoreDir()). The user will be prompted for a password.
Returns the imported account.
func (*MassaAccount) Addr ¶
func (m *MassaAccount) Addr() string
type MassaClient ¶
type MassaClient struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(optFns ...massaClientOptFunc) *MassaClient
func (*MassaClient) CallSC ¶
func (c *MassaClient) CallSC(callerAddr, targetAddr, targetFunc string, params []byte, coins uint64) (opId string, err error)
Calls a target smart contract with the provided call data from the caller address.
Returns the operationId of the call, as well as an error in the event of failure.
func (*MassaClient) ImportFromPriv ¶
func (c *MassaClient) ImportFromPriv(privEncoded, password string) (addr string, err error)
func (*MassaClient) Init ¶
func (c *MassaClient) Init(jsonRpcUrls ...string) error
func (*MassaClient) SendTransaction ¶
func (c *MassaClient) SendTransaction(sender, recipientAddr string, amount uint64) (opId string, err error)
Sends a transaction from the sender address to the recipient address.
The amount argument should be a value in nanoMassa.
Returns the operationId of the transacton as well as an error on failure.
type MassaSignature ¶
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
func (*Operation) Type ¶
func (o *Operation) Type() OperationType
type OperationData ¶
type OperationData interface { Type() OperationType // contains filtered or unexported methods }
type OperationType ¶
type OperationType int
const ( OpType_Transaction OperationType = iota OpType_BuyRoll OpType_SellRoll OpType_ExecuteSC OpType_CallSC )
type RegisteredAccount ¶
type RpcType ¶
type RpcType int
RpcType is an enum that represents one of two types of RPC that is available on each ApiProvider
type TxData ¶
type TxData struct {
// contains filtered or unexported fields
}
func (TxData) Type ¶
func (t TxData) Type() OperationType
type UnlockedAccount ¶
type UnlockedAccount struct { // Name string *MassaAccount }
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
func (*Wallet) GenerateAccount ¶
TODO: Unit tests... Generates a new Massa Account, saves the keystore file, and registers the account with the wallet registry.
In the case where an empty string "" is provided as the password, the user will be prompted to imput a password.
Returns the address of the generated account and an error.
func (*Wallet) GetWalletHome ¶
func (*Wallet) ImportFromFile ¶
TODO: Unit tests... Derives a single account from the keystore file, registers the account with the wallet registry, and unlocks the account.
In the case where an empty string "" is provided as the password, the user will be prompted to imput a password.
Returns the address of the imported account and an error.
func (*Wallet) ImportFromPriv ¶
TODO: Unit tests... Derives a single account from the prefixed and base58 encoded private key, persists it to disk, registers it with the wallet registry and unlocks the wallet.
In the case where an empty string "" is provided as the password, the user will be prompted to imput a password.
Returns the address of the imported account and an error.
func (*Wallet) Init ¶
This function creates the wallet home directory if it is not already present and creates a registry file that keeps track of which accounts have been previously imported.
func (*Wallet) KeystoreDir ¶
func (*Wallet) ListUnlockedAccounts ¶
func (*Wallet) SignMessage ¶
func (w *Wallet) SignMessage(addr string, msg string) (MassaSignature, error)
Takes an arbitrary message and signs the blake3 digest of it's utf-8 decoded bytes.
func (*Wallet) UnlockAccount ¶
TODO: Unit tests... Unlocks the account corresponding to the provided address. If the account is not registered or the wallet file is not present an error will be returned.