Documentation ¶
Index ¶
- func DisableLog()
- func GenerateP256PrivateKey() []byte
- func GeneratePrivateKey(curve elliptic.Curve) []byte
- func GetP256PublicKey(privateKey []byte) *PublicKey
- func GetPublicKey(curve elliptic.Curve, privateKey []byte) *PublicKey
- func UseLogger(logger elalog.Logger)
- type Account
- type AddrFilter
- func (filter *AddrFilter) AddAddr(addr *common.Uint168)
- func (filter *AddrFilter) Clear()
- func (filter *AddrFilter) ContainAddr(hash common.Uint168) bool
- func (filter *AddrFilter) DeleteAddr(hash common.Uint168)
- func (filter *AddrFilter) GetAddrs() []*common.Uint168
- func (filter *AddrFilter) IsLoaded() bool
- func (filter *AddrFilter) LoadAddrs(addrs []*common.Uint168)
- type Config
- type IService
- type StateNotifier
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 ¶
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 ¶
Get the public key of the given private key on the specified ECC curve
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 ¶
Get a standard ELA account by the given private key and ECC curve
func GetP256Account ¶
Get a standard ELA account by the given private key on ECC P256 curve
func NewAccount ¶
Create an account instance with private key and public key
func (*Account) ProgramHash ¶
Get account program hash
type AddrFilter ¶
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.Params // 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() 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 }
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 ¶
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.