Documentation
¶
Index ¶
- Constants
- Variables
- func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error
- func FloatToWei(val float64, decimals int) *big.Int
- func Forever(f func(), period time.Duration)
- func GasPrice() *big.Int
- func GenArgsAbi(args string) (string, bool)
- func GenContractData(strs ...string) (string, bool)
- func GenTransferCode(toAddress string, amount *big.Int) ([]byte, error)
- func GetBalance(address string) (string, error)
- func GetNonceAt(address string) uint64
- func Init() error
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, ...)
- func MustParseDerivationPath(path string) accounts.DerivationPath
- func NewMnemonic(bits int) (string, error)
- func NewSeed() ([]byte, error)
- func NewSeedFromMnemonic(mnemonic string) ([]byte, error)
- func NonSlidingUntil(f func(), period time.Duration, stopCh <-chan struct{})
- func ParseDerivationPath(path string) (accounts.DerivationPath, error)
- func PendingNonce(address string) (uint64, error)
- func Poll(interval, timeout time.Duration, condition ConditionFunc) error
- func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error
- func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error
- func PollInfinite(interval time.Duration, condition ConditionFunc) error
- func PollUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error
- func SendEthCoins(to string, nonce uint64, amountWei *big.Int, priv *ecdsa.PrivateKey, ...) (string, error)
- func SendEthTokens(address, to string, nonce uint64, amount *big.Int, priv *ecdsa.PrivateKey, ...) (string, error)
- func SendRawTransaction(address string, inputData []byte, nonce uint64, priv *ecdsa.PrivateKey, ...) (string, error)
- func SetGasPrice(gasPrice *big.Int)
- func StringToWei(val string, decimals int) *big.Int
- func ToHexInt(n *big.Int) string
- func Until(f func(), period time.Duration, stopCh <-chan struct{})
- func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error
- type Address
- type Backoff
- type ConditionFunc
- type Conn
- type Group
- type Keystore
- func (ks *Keystore) CheckPassphrase(keyjson []byte, passphrase string) (bool, error)
- func (ks *Keystore) GenKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *keystore.Key
- func (ks *Keystore) GenKeystore(key *keystore.Key, passphrase string) ([]byte, error)
- func (ks *Keystore) NewKey() (*keystore.Key, error)
- func (ks *Keystore) SignTx(keyjson []byte, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
- func (ks *Keystore) Update(keyjson []byte, passphrase, newPassphrase string) ([]byte, error)
- type WaitFunc
- type Wallet
- func (w *Wallet) Accounts() []accounts.Account
- func (w *Wallet) Address(account accounts.Account) (common.Address, error)
- func (w *Wallet) AddressBytes(account accounts.Account) ([]byte, error)
- func (w *Wallet) AddressHex(account accounts.Account) (string, error)
- func (w *Wallet) Close() error
- func (w *Wallet) Contains(account accounts.Account) bool
- func (w *Wallet) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error)
- func (w *Wallet) Open(passphrase string) error
- func (w *Wallet) Path(account accounts.Account) (string, error)
- func (w *Wallet) PrivateKey(account accounts.Account) (*ecdsa.PrivateKey, error)
- func (w *Wallet) PrivateKeyBytes(account accounts.Account) ([]byte, error)
- func (w *Wallet) PrivateKeyHex(account accounts.Account) (string, error)
- func (w *Wallet) PublicKey(account accounts.Account) (*ecdsa.PublicKey, error)
- func (w *Wallet) PublicKeyBytes(account accounts.Account) ([]byte, error)
- func (w *Wallet) PublicKeyHex(account accounts.Account) (string, error)
- func (w *Wallet) SelfDerive(base accounts.DerivationPath, chain ethereum_core.ChainStateReader)
- func (w *Wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error)
- func (w *Wallet) SignHashWithPassphrase(account accounts.Account, passphrase string, hash []byte) ([]byte, error)
- func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
- func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, ...) (*types.Transaction, error)
- func (w *Wallet) Status() (string, error)
- func (w *Wallet) URL() accounts.URL
- func (w *Wallet) Unpin(account accounts.Account) error
Constants ¶
const ( // StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptN = 1 << 18 // StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptP = 1 // LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB // memory and taking approximately 100ms CPU time on a modern processor. LightScryptN = 1 << 12 // LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB // memory and taking approximately 100ms CPU time on a modern processor. LightScryptP = 6 // VeryLightScryptN VeryLightScryptN VeryLightScryptN = 2 // VeryLightScryptP VeryLightScryptP VeryLightScryptP = 1 )
Variables ¶
var Clients = &Conn{}
Clients global client connection
var DefaultBaseDerivationPath = accounts.DefaultBaseDerivationPath
DefaultBaseDerivationPath is the base path from which custom derivation endpoints are incremented. As such, the first account will be at m/44'/60'/0'/0, the second at m/44'/60'/0'/1, etc
var DefaultRootDerivationPath = accounts.DefaultRootDerivationPath
DefaultRootDerivationPath is the root path to which custom derivation endpoints are appended. As such, the first account will be at m/44'/60'/0'/0, the second at m/44'/60'/0'/1, etc.
var ErrWaitTimeout = errors.New("timed out waiting for the condition")
ErrWaitTimeout is returned when the condition exited without success.
var ForeverTestTimeout = time.Second * 30
ForeverTestTimeout ForeverTestTimeout
... <- time.After(timeout): t.Errorf("Timed out")
The value for timeout should effectively be "forever." Obviously we don't want our tests to truly lock up forever, but 30s is long enough that it is effectively forever for the things that can slow down a run on a heavily contended machine (GC, seeks, etc), but not so long as to make a developer ctrl-c a test run if they do happen to break that test.
var NeverStop <-chan struct{} = make(chan struct{})
NeverStop may be passed to Until to make it never stop.
Functions ¶
func ExponentialBackoff ¶
func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error
ExponentialBackoff repeats a condition check with exponential backoff.
It checks the condition up to Steps times, increasing the wait by multiplying the previous duration by Factor.
If Jitter is greater than zero, a random amount of each duration is added (between duration and duration*(1+jitter)).
If the condition never returns true, ErrWaitTimeout is returned. All other errors terminate immediately.
func FloatToWei ¶
FloatToWei 传入值和精度, 对于以太来说是返回amount Wei
func GenContractData ¶
GenContractData GenContractData
func GenTransferCode ¶
GenTransferCode gen token transfer data
func Jitter ¶
Jitter returns a time.Duration between duration and duration + maxFactor * duration.
This allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.
func JitterUntil ¶
func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh <-chan struct{})
JitterUntil loops until stop channel is closed, running f every period.
If jitterFactor is positive, the period is jittered before every run of f. If jitterFactor is not positive, the period is unchanged and not jittered.
If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.
Close stopCh to stop. f may not be invoked if stop channel is already closed. Pass NeverStop to if you don't want it stop.
func MustParseDerivationPath ¶
func MustParseDerivationPath(path string) accounts.DerivationPath
MustParseDerivationPath parses the derivation path in string format into []uint32 but will panic if it can't parse it.
func NewMnemonic ¶
NewMnemonic returns a randomly generated BIP-39 mnemonic using 128-256 bits of entropy.
func NewSeedFromMnemonic ¶
NewSeedFromMnemonic returns a BIP-39 seed based on a BIP-39 mnemonic.
func NonSlidingUntil ¶
NonSlidingUntil loops until stop channel is closed, running f every period.
NonSlidingUntil is syntactic sugar on top of JitterUntil with zero jitter factor, with sliding = false (meaning the timer for period starts at the same time as the function starts).
func ParseDerivationPath ¶
func ParseDerivationPath(path string) (accounts.DerivationPath, error)
ParseDerivationPath parses the derivation path in string format into []uint32
func PendingNonce ¶
PendingNonce TODO nonce 理论上非并发安全
func Poll ¶
func Poll(interval, timeout time.Duration, condition ConditionFunc) error
Poll tries a condition func until it returns true, an error, or the timeout is reached.
Poll always waits the interval before the run of 'condition'. 'condition' will always be invoked at least once.
Some intervals may be missed if the condition takes too long or the time window is too short.
If you want to Poll something forever, see PollInfinite.
func PollImmediate ¶
func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error
PollImmediate tries a condition func until it returns true, an error, or the timeout is reached.
Poll always checks 'condition' before waiting for the interval. 'condition' will always be invoked at least once.
Some intervals may be missed if the condition takes too long or the time window is too short.
If you want to Poll something forever, see PollInfinite.
func PollImmediateInfinite ¶
func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error
PollImmediateInfinite tries a condition func until it returns true or an error
PollImmediateInfinite runs the 'condition' before waiting for the interval.
Some intervals may be missed if the condition takes too long or the time window is too short.
func PollInfinite ¶
func PollInfinite(interval time.Duration, condition ConditionFunc) error
PollInfinite tries a condition func until it returns true or an error
PollInfinite always waits the interval before the run of 'condition'.
Some intervals may be missed if the condition takes too long or the time window is too short.
func PollUntil ¶
func PollUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error
PollUntil tries a condition func until it returns true, an error or stopCh is closed.
PolUntil always waits interval before the first run of 'condition'. 'condition' will always be invoked at least once.
func SendEthCoins ¶
func SendEthCoins(to string, nonce uint64, amountWei *big.Int, priv *ecdsa.PrivateKey, chainID *big.Int, data []byte) (string, error)
SendEthCoins SendEthCoins
func SendEthTokens ¶
func SendEthTokens(address, to string, nonce uint64, amount *big.Int, priv *ecdsa.PrivateKey, chainID *big.Int) (string, error)
SendEthTokens SendEthTokens
func SendRawTransaction ¶
func SendRawTransaction(address string, inputData []byte, nonce uint64, priv *ecdsa.PrivateKey, chainID, gasPrice *big.Int) (string, error)
SendRawTransaction SendRawTransaction
func StringToWei ¶
StringToWei 传入值和精度, 对于以太来说是返回amount Wei
func Until ¶
Until loops until stop channel is closed, running f every period.
Until is syntactic sugar on top of JitterUntil with zero jitter factor and with sliding = true (which means the timer for period starts after the f completes).
func WaitFor ¶
func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error
WaitFor continually checks 'fn' as driven by 'wait'.
WaitFor gets a channel from 'wait()”, and then invokes 'fn' once for every value placed on the channel and once more when the channel is closed.
If 'fn' returns an error the loop ends and that error is returned, and if 'fn' returns true the loop ends and nil is returned.
ErrWaitTimeout will be returned if the channel is closed without fn ever returning true.
Types ¶
type Address ¶
type Address struct { // Wif string `json:"address"` ID string `json:"id" ` UserName string `json:"username" form:"username"` Label string `json:"label" form:"label"` Private string `json:"private"` Public string `json:"public"` }
Address eth地址结构
type Backoff ¶
type Backoff struct { Duration time.Duration // the base duration Factor float64 // Duration is multiplied by factor each iteration Jitter float64 // The amount of jitter applied each iteration Steps int // Exit with error after this many steps }
Backoff holds parameters applied to a Backoff function.
type ConditionFunc ¶
ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group allows to start a group of goroutines and wait for their completion.
func (*Group) Start ¶
func (g *Group) Start(f func())
Start starts f in a new goroutine in the group.
func (*Group) StartWithChannel ¶
func (g *Group) StartWithChannel(stopCh <-chan struct{}, f func(stopCh <-chan struct{}))
StartWithChannel starts f in a new goroutine in the group. stopCh is passed to f as an argument. f should stop when stopCh is available.
func (*Group) StartWithContext ¶
StartWithContext starts f in a new goroutine in the group. ctx is passed to f as an argument. f should stop when ctx.Done() is available.
type Keystore ¶
type Keystore struct { }
Keystore Keystore
var Ks Keystore
Ks Keystore
func (*Keystore) CheckPassphrase ¶
CheckPassphrase CheckPassphrase
func (*Keystore) GenKeyFromECDSA ¶
func (ks *Keystore) GenKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *keystore.Key
GenKeyFromECDSA GenKeyFromECDSA
func (*Keystore) GenKeystore ¶
GenKeystore GenKeystore
type WaitFunc ¶
type WaitFunc func(done <-chan struct{}) <-chan struct{}
WaitFunc creates a channel that receives an item every time a test should be executed and is closed when the last test should be invoked.
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
Wallet is the underlying wallet struct.
func NewFromMnemonic ¶
NewFromMnemonic returns a new wallet from a BIP-39 mnemonic.
func NewFromSeed ¶
NewFromSeed returns a new wallet from a BIP-39 seed.
func (*Wallet) Accounts ¶
Accounts implements accounts.Wallet, returning the list of accounts pinned to the wallet. If self-derivation was enabled, the account list is periodically expanded based on current chain state.
func (*Wallet) AddressBytes ¶
AddressBytes returns the address in bytes format of the account.
func (*Wallet) AddressHex ¶
AddressHex returns the address in hex string format of the account.
func (*Wallet) Close ¶
Close implements accounts.Wallet, however this does nothing since this is not a hardware device.
func (*Wallet) Contains ¶
Contains implements accounts.Wallet, returning whether a particular account is or is not pinned into this wallet instance.
func (*Wallet) Derive ¶
Derive implements accounts.Wallet, deriving a new account at the specific derivation path. If pin is set to true, the account will be added to the list of tracked accounts.
func (*Wallet) Open ¶
Open implements accounts.Wallet, however this does nothing since this is not a hardware device.
func (*Wallet) PrivateKey ¶
PrivateKey returns the ECDSA private key of the account.
func (*Wallet) PrivateKeyBytes ¶
PrivateKeyBytes returns the ECDSA private key in bytes format of the account.
func (*Wallet) PrivateKeyHex ¶
PrivateKeyHex return the ECDSA private key in hex string format of the account.
func (*Wallet) PublicKeyBytes ¶
PublicKeyBytes returns the ECDSA public key in bytes format of the account.
func (*Wallet) PublicKeyHex ¶
PublicKeyHex return the ECDSA public key in hex string format of the account.
func (*Wallet) SelfDerive ¶
func (w *Wallet) SelfDerive(base accounts.DerivationPath, chain ethereum_core.ChainStateReader)
SelfDerive implements accounts.Wallet, trying to discover accounts that the user used previously (based on the chain state), but ones that he/she did not explicitly pin to the wallet manually. To avoid chain head monitoring, self derivation only runs during account listing (and even then throttled).
func (*Wallet) SignHashWithPassphrase ¶
func (w *Wallet) SignHashWithPassphrase(account accounts.Account, passphrase string, hash []byte) ([]byte, error)
SignHashWithPassphrase implements accounts.Wallet, attempting to sign the given hash with the given account using the passphrase as extra authentication.
func (*Wallet) SignTx ¶
func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
SignTx implements accounts.Wallet, which allows the account to sign an Ethereum transaction.
func (*Wallet) SignTxWithPassphrase ¶
func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
SignTxWithPassphrase implements accounts.Wallet, attempting to sign the given transaction with the given account using passphrase as extra authentication.
func (*Wallet) Status ¶
Status implements accounts.Wallet, returning a custom status message from the underlying vendor-specific hardware wallet implementation, however this does nothing since this is not a hardware device.