本文整理匯總了Golang中github.com/ethereum/go-ethereum/core/types.Transaction.SetNonce方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transaction.SetNonce方法的具體用法?Golang Transaction.SetNonce怎麽用?Golang Transaction.SetNonce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ethereum/go-ethereum/core/types.Transaction
的用法示例。
在下文中一共展示了Transaction.SetNonce方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Transact
func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
// this minimalistic recoding is enough (works for natspec.js)
var jsontx = fmt.Sprintf(`{"params":[{"to":"%s","data": "%s"}]}`, toStr, codeStr)
if !self.ConfirmTransaction(jsontx) {
err := fmt.Errorf("Transaction not confirmed")
return "", err
}
var (
from = common.HexToAddress(fromStr)
to = common.HexToAddress(toStr)
value = common.NewValue(valueStr)
gas = common.Big(gasStr)
price = common.Big(gasPriceStr)
data []byte
contractCreation bool
)
// TODO if no_private_key then
//if _, exists := p.register[args.From]; exists {
// p.register[args.From] = append(p.register[args.From], args)
//} else {
/*
account := accounts.Get(common.FromHex(args.From))
if account != nil {
if account.Unlocked() {
if !unlockAccount(account) {
return
}
}
result, _ := account.Transact(common.FromHex(args.To), common.FromHex(args.Value), common.FromHex(args.Gas), common.FromHex(args.GasPrice), common.FromHex(args.Data))
if len(result) > 0 {
*reply = common.ToHex(result)
}
} else if _, exists := p.register[args.From]; exists {
p.register[ags.From] = append(p.register[args.From], args)
}
*/
// TODO: align default values to have the same type, e.g. not depend on
// common.Value conversions later on
if gas.Cmp(big.NewInt(0)) == 0 {
gas = DefaultGas()
}
if price.Cmp(big.NewInt(0)) == 0 {
price = DefaultGasPrice()
}
data = common.FromHex(codeStr)
if len(toStr) == 0 {
contractCreation = true
}
var tx *types.Transaction
if contractCreation {
tx = types.NewContractCreationTx(value.BigInt(), gas, price, data)
} else {
tx = types.NewTransactionMessage(to, value.BigInt(), gas, price, data)
}
state := self.backend.ChainManager().TxState()
var nonce uint64
if len(nonceStr) != 0 {
nonce = common.Big(nonceStr).Uint64()
} else {
nonce = state.NewNonce(from)
}
tx.SetNonce(nonce)
if err := self.sign(tx, from, false); err != nil {
return "", err
}
if err := self.backend.TxPool().Add(tx); err != nil {
return "", err
}
if contractCreation {
addr := core.AddressFromMessage(tx)
glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
return core.AddressFromMessage(tx).Hex(), nil
} else {
glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
}
return tx.Hash().Hex(), nil
}