sdk

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 25 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func GenerateP256PrivateKey

func GenerateP256PrivateKey() []byte

Generate a ECC private key on ECC P256 curve

func GeneratePrivateKey

func GeneratePrivateKey(curve elliptic.Curve) []byte

Generate a ECC private key by the given curve

func GetP256PublicKey

func GetP256PublicKey(privateKey []byte) *PublicKey

Get the public key of the given private key on ECC P256 curve

func GetPublicKey

func GetPublicKey(curve elliptic.Curve, privateKey []byte) *PublicKey

Get the public key of the given private key on the specified ECC curve

func UseLogger

func UseLogger(logger elalog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using elalog.

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

A ELA standard account is a set of private key, public key, redeem script, program hash and address data. redeem script is (script content length)+(script content)+(script type), program hash is the sha256 value of redeem script and converted to ripemd160 format with a (Type) prefix. address is the base58 format of program hash, which is the string value show up on user interface as account address. With account, you can get the transfer address or sign transaction etc.

func GetAccount

func GetAccount(curve elliptic.Curve, privateKey []byte) *Account

Get a standard ELA account by the given private key and ECC curve

func GetP256Account

func GetP256Account(privateKey []byte) *Account

Get a standard ELA account by the given private key on ECC P256 curve

func NewAccount

func NewAccount(privateKey []byte, publicKey *crypto.PublicKey) (*Account, error)

Create an account instance with private key and public key

func (*Account) Address

func (a *Account) Address() string

Get account address

func (*Account) PrivateKey

func (a *Account) PrivateKey() []byte

Get account private key

func (*Account) ProgramHash

func (a *Account) ProgramHash() *common.Uint168

Get account program hash

func (*Account) PublicKey

func (a *Account) PublicKey() *crypto.PublicKey

Get account public key

func (*Account) RedeemScript

func (a *Account) RedeemScript() []byte

Get account redeem script

func (*Account) Sign

func (a *Account) Sign(data []byte) ([]byte, error)

Sign data with account

type AddrFilter

type AddrFilter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

This is a helper class to filter interested addresses when synchronize transactions or get cached addresses list to build a bloom filter instead of load addresses from database every time.

func NewAddrFilter

func NewAddrFilter(addrs []*common.Uint168) *AddrFilter

Create a AddrFilter instance, you can pass all the addresses through this method or pass nil and use AddAddr() method to add interested addresses later.

func (*AddrFilter) AddAddr

func (filter *AddrFilter) AddAddr(addr *common.Uint168)

Add a interested address into this Filter

func (*AddrFilter) Clear

func (filter *AddrFilter) Clear()

func (*AddrFilter) ContainAddr

func (filter *AddrFilter) ContainAddr(hash common.Uint168) bool

Check if an address was added into this filter as a interested address

func (*AddrFilter) DeleteAddr

func (filter *AddrFilter) DeleteAddr(hash common.Uint168)

Remove an address from this Filter

func (*AddrFilter) GetAddrs

func (filter *AddrFilter) GetAddrs() []*common.Uint168

Get addresses that were added into this Filter

func (*AddrFilter) IsLoaded

func (filter *AddrFilter) IsLoaded() bool

Check if addresses are loaded into this Filter

func (*AddrFilter) LoadAddrs

func (filter *AddrFilter) LoadAddrs(addrs []*common.Uint168)

Load or reload all the interested addresses into the AddrFilter

type Config

type Config struct {
	// DataDir is the data path to store peer addresses etc.
	DataDir string

	// ChainParams indicates the network parameters for the SPV service.
	ChainParams *config.Configuration

	// PermanentPeers are the peers need to be connected permanently.
	PermanentPeers []string

	// CandidateFlags defines flags needed for a sync candidate.
	CandidateFlags []uint64

	// GenesisHeader is the
	GenesisHeader util.BlockHeader

	// The database to store all block headers
	ChainStore database.ChainStore

	// NewTransaction create a new transaction instance.
	NewTransaction func(r io.Reader) util.Transaction

	// NewBlockHeader create a new block header instance.
	NewBlockHeader func() util.BlockHeader

	// GetTxFilter() returns a transaction filter like a bloom filter or others.
	GetTxFilter func() *msg.TxFilterLoad

	// StateNotifier is an optional config, if you don't want to receive state changes of transactions
	// or blocks, just keep it blank.
	StateNotifier StateNotifier

	//node version
	NodeVersion string
}

Config is the configuration settings to the SPV service.

type IService

type IService interface {
	// Start SPV service
	Start()

	// Stop SPV service
	Stop()

	// IsCurrent returns whether or not the SPV service believes it is synced with
	// the connected peers.
	IsCurrent() bool

	// UpdateFilter is a trigger to make SPV service refresh the current
	// transaction filer(in our implementation the bloom filter) and broadcast the
	// new filter to connected peers.  This will invoke the GetFilterData() method
	// in Config.
	UpdateFilter()

	// SendTransaction broadcast a transaction message to the peer to peer network.
	SendTransaction(util.Transaction) error
}

IService is an implementation for SPV features.

func NewService

func NewService(config *Config) (IService, error)

NewService returns a new SPV service instance. there are two implementations you need to do, DataStore and GetBloomFilter() method. DataStore is an interface including all methods you need to implement placed in db/datastore.go. Also an sample APP spvwallet is contain in this project placed in spvwallet folder.

type StateNotifier

type StateNotifier interface {
	// TransactionAnnounce will be invoked when received a new announced transaction.
	TransactionAnnounce(tx util.Transaction)

	// TransactionAccepted will be invoked after a transaction sent by
	// SendTransaction() method has been accepted.  Notice: this method needs at
	// lest two connected peers to work.
	TransactionAccepted(tx util.Transaction)

	// TransactionRejected will be invoked if a transaction sent by SendTransaction()
	// method has been rejected.
	TransactionRejected(tx util.Transaction)

	// TransactionConfirmed will be invoked after a transaction sent by
	// SendTransaction() method has been packed into a block.
	TransactionConfirmed(tx *util.Tx)

	// BlockCommitted will be invoked when a block and transactions within it are
	// successfully committed into database.
	BlockCommitted(block *util.Block)
}

StateNotifier exposes methods to notify status changes of transactions and blocks.

type TxTypesFilter added in v0.1.0

type TxTypesFilter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

This is a helper class to filter interested tx types when synchronize transactions or get cached tx types list to build a bloom filter instead of load tx types from database every time.

func NewTxTypesFilter added in v0.1.0

func NewTxTypesFilter(txTypes []uint8) *TxTypesFilter

Create a TxTypesFilter instance, you can pass all the tx types through this method or pass nil and use AddTxType() method to add interested tx types later.

func (*TxTypesFilter) AddTxType added in v0.1.0

func (filter *TxTypesFilter) AddTxType(txType uint8)

Add a interested transaction type into this Filter

func (*TxTypesFilter) Clear added in v0.1.0

func (filter *TxTypesFilter) Clear()

func (*TxTypesFilter) ContainTxType added in v0.1.0

func (filter *TxTypesFilter) ContainTxType(txType uint8) bool

Check if a transaction type was added into this filter as a interested tx type

func (*TxTypesFilter) DeleteTxType added in v0.1.0

func (filter *TxTypesFilter) DeleteTxType(txType uint8)

Remove a transaction type from this Filter

func (*TxTypesFilter) GetTxTypes added in v0.1.0

func (filter *TxTypesFilter) GetTxTypes() []uint8

Get transaction types that were added into this Filter

func (*TxTypesFilter) IsLoaded added in v0.1.0

func (filter *TxTypesFilter) IsLoaded() bool

Check if transaction types are loaded into this Filter

func (*TxTypesFilter) LoadTxTypes added in v0.1.0

func (filter *TxTypesFilter) LoadTxTypes(txTypes []uint8)

Load or reload all the interested transaction types into the TxTypesFilter

Jump to

Keyboard shortcuts

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