lib

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound    = errors.New("account not found in account map of transaction manager")
	ErrInvalidPayLoadType = errors.New("invalid payload type")
	ErrInvalidNetworkType = errors.New("invalid network type")
)

Functions

func PACToSatoshiPAC

func PACToSatoshiPAC(coin float64) int64

converting PAC coin amount to satoshi amount.

func SatoshiPACtoPAC

func SatoshiPACtoPAC(change int64) float64

converting satoshi amount to PAC coin amount.

Types

type Account

type Account struct {
	PrivateKey *bls.PrivateKey
	PublicKey  *bls.PublicKey
	Address    crypto.Address
}

Account is a keeps a Pactus account private key, public key and address.

type NetworkType

type NetworkType int

NetworkType is a type that determine which network you are using.

const (
	// TestNet network type is Pactus testnet.
	TestNet NetworkType = 0

	// MainNet network type is Pactus mainnet.
	MainNet NetworkType = 1
)

type Tx

type Tx struct {
	RawTx    []byte
	SignedTx []byte

	// ID will be filled when Send method called.
	ID []byte
}

Tx struct contains a specific transaction signed bytes and raw transaction bytes.

func (*Tx) GetData

func (tx *Tx) GetData(ctx context.Context, tm TxManager) (*pactus.GetTransactionResponse, error)

GetData will get a transaction data from network.

func (*Tx) GetInfo

func (tx *Tx) GetInfo(ctx context.Context, tm TxManager) (*pactus.GetTransactionResponse, error)

GetInfo will get a transaction info from network.

func (*Tx) Raw

func (tx *Tx) Raw() []byte

Raw returns bytes of a raw (unsigned) transaction.

func (*Tx) Send

func (tx *Tx) Send(ctx context.Context, tm *TxManager) ([]byte, error)

Send sends (publish, broadcasts) a transaction to the network using RPC node urls.

func (*Tx) Signed

func (tx *Tx) Signed() []byte

Signed returns bytes of transaction which is signed by a private key and have a signature.

type TxManager

type TxManager struct {
	// Provider is a RPC node url for sending and getting data from.
	Provider string

	// RPCClient is a Client for Pactus gRPC service.
	RPCClient *client.Client

	// PrivateKey is the private key of account on behalf of which transactions are made and sent.
	Accounts map[string]Account

	// NetworkType helps to determine which address prefixes and HRPs should be used, like: pc, tpc and more.
	NetworkType NetworkType
}

TxManager helps you to make, send and work with transaction in Pactus Blockchain.

func NewTxManager

func NewTxManager(networkType NetworkType, rpcURL, privatekey, firstAccountName string) (*TxManager, error)

NewTxManager returns a TxManager by provided parameters.

func (*TxManager) AddAccount

func (tm *TxManager) AddAccount(privateKey, name string) error

AddAccount get a name and private key as input and add a new account to the transaction manager accounts list.

func (*TxManager) CalcFee

func (tm *TxManager) CalcFee(ctx context.Context, amt int64, payloadType string) (int64, error)

func (*TxManager) Close

func (tm *TxManager) Close() error

Close will close all connections and ... in a transaction manager.

func (*TxManager) MakeBondTransaction

func (tm *TxManager) MakeBondTransaction(ctx context.Context, stake int64,
	receiverAddr string, lockTime uint32, memo, accName string,
) (Tx, error)

MakeBondTransaction makes a signed Bond transaction.

func (*TxManager) MakeTransferTransaction

func (tm *TxManager) MakeTransferTransaction(ctx context.Context, amt int64,
	receiverAddr string, lockTime uint32, memo, accName string,
) (Tx, error)

MakeTransferTransaction makes a signed Transfer transaction.

func (*TxManager) MakeUnBondTransaction

func (tm *TxManager) MakeUnBondTransaction(validatorAddr string, lockTime uint32,
	memo, accName string,
) (Tx, error)

MakeUnBondTransaction makes a signed UnBond transaction.

func (*TxManager) MakeUnsignedBondTransaction

func (tm *TxManager) MakeUnsignedBondTransaction(ctx context.Context, stake int64,
	receiverAddr string, lockTime uint32, memo, accName string,
) (Tx, error)

MakeUnsignedBondTransaction makes a unsigned (raw) Bond transaction.

func (*TxManager) MakeUnsignedTransferTransaction

func (tm *TxManager) MakeUnsignedTransferTransaction(ctx context.Context, amt int64,
	receiverAddr string, lockTime uint32, memo, accName string,
) (Tx, error)

MakeUnsignedTransferTransaction makes a unsigned (raw) Transfer transaction.

func (*TxManager) MakeUnsignedUnBondTransaction

func (tm *TxManager) MakeUnsignedUnBondTransaction(validatorAddr string, lockTime uint32, memo string,
) (Tx, error)

MakeUnsignedUnBondTransaction makes a unsigned (raw) UnBond transaction.

func (*TxManager) MakeUnsignedWithdrawTransaction

func (tm *TxManager) MakeUnsignedWithdrawTransaction(ctx context.Context,
	validatorAddr, accountAddr string, amt int64, lockTime uint32, memo string,
) (Tx, error)

MakeUnsignedWithdrawTransaction makes a unsigned (raw) Withdraw transaction.

func (*TxManager) MakeWithdrawTransaction

func (tm *TxManager) MakeWithdrawTransaction(ctx context.Context,
	validatorAddr, accountAddr string, amt int64, lockTime uint32, memo, accName string,
) (Tx, error)

MakeWithdrawTransaction makes a signed Withdraw transaction.

Jump to

Keyboard shortcuts

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