本文整理汇总了Golang中github.com/tendermint/tendermint/account.Account类的典型用法代码示例。如果您正苦于以下问题:Golang Account类的具体用法?Golang Account怎么用?Golang Account使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Account类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: testSNativeCALL
func testSNativeCALL(t *testing.T, expectPass bool, blockCache *BlockCache, doug *acm.Account, snativeAddress, data []byte, f func([]byte) error) {
if expectPass {
perm, err := ptypes.PermStringToFlag(TrimmedString(snativeAddress))
if err != nil {
t.Fatal(err)
}
doug.Permissions.Base.Set(perm, true)
}
var addr []byte
contractCode := callContractCode(snativeAddress)
doug.Code = contractCode
blockCache.UpdateAccount(doug)
addr = doug.Address
tx, _ := types.NewCallTx(blockCache, user[0].PubKey, addr, data, 100, 10000, 100)
tx.Sign(chainID, user[0])
fmt.Println("subscribing to", types.EventStringAccCall(snativeAddress))
ev, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(snativeAddress))
if exception == ExceptionTimeOut {
t.Fatal("Timed out waiting for event")
}
if expectPass {
if exception != "" {
t.Fatal("Unexpected exception", exception)
}
evv := ev.(types.EventDataCall)
ret := evv.Return
if err := f(ret); err != nil {
t.Fatal(err)
}
} else {
if exception == "" {
t.Fatal("Expected exception")
}
}
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:35,代码来源:permissions_test.go
示例2: checkInputPubKey
func checkInputPubKey(acc *acm.Account, in *types.TxInput) error {
if acc.PubKey == nil {
if in.PubKey == nil {
return types.ErrTxUnknownPubKey
}
if !bytes.Equal(in.PubKey.Address(), acc.Address) {
return types.ErrTxInvalidPubKey
}
acc.PubKey = in.PubKey
} else {
in.PubKey = nil
}
return nil
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:14,代码来源:execution.go
示例3: UpdateAccount
// The account is copied before setting, so mutating it
// afterwards has no side effects.
// Implements Statelike
func (s *State) UpdateAccount(account *acm.Account) bool {
return s.accounts.Set(account.Address, account.Copy())
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:6,代码来源:state.go
示例4: ExecTx
// If the tx is invalid, an error will be returned.
// Unlike ExecBlock(), state will not be altered.
func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireable) (err error) {
// TODO: do something with fees
fees := int64(0)
_s := blockCache.State() // hack to access validators and block height
// Exec tx
switch tx := tx.(type) {
case *types.SendTx:
accounts, err := getInputs(blockCache, tx.Inputs)
if err != nil {
return err
}
// ensure all inputs have send permissions
if !hasSendPermission(blockCache, accounts) {
return fmt.Errorf("At least one input lacks permission for SendTx")
}
// add outputs to accounts map
// if any outputs don't exist, all inputs must have CreateAccount perm
accounts, err = getOrMakeOutputs(blockCache, accounts, tx.Outputs)
if err != nil {
return err
}
signBytes := acm.SignBytes(_s.ChainID, tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil {
return err
}
outTotal, err := validateOutputs(tx.Outputs)
if err != nil {
return err
}
if outTotal > inTotal {
return types.ErrTxInsufficientFunds
}
fee := inTotal - outTotal
fees += fee
// Good! Adjust accounts
adjustByInputs(accounts, tx.Inputs)
adjustByOutputs(accounts, tx.Outputs)
for _, acc := range accounts {
blockCache.UpdateAccount(acc)
}
// if the evc is nil, nothing will happen
if evc != nil {
for _, i := range tx.Inputs {
evc.FireEvent(types.EventStringAccInput(i.Address), types.EventDataTx{tx, nil, ""})
}
for _, o := range tx.Outputs {
evc.FireEvent(types.EventStringAccOutput(o.Address), types.EventDataTx{tx, nil, ""})
}
}
return nil
case *types.CallTx:
var inAcc, outAcc *acm.Account
// Validate input
inAcc = blockCache.GetAccount(tx.Input.Address)
if inAcc == nil {
log.Info(Fmt("Can't find in account %X", tx.Input.Address))
return types.ErrTxInvalidAddress
}
createContract := len(tx.Address) == 0
if createContract {
if !hasCreateContractPermission(blockCache, inAcc) {
return fmt.Errorf("Account %X does not have CreateContract permission", tx.Input.Address)
}
} else {
if !hasCallPermission(blockCache, inAcc) {
return fmt.Errorf("Account %X does not have Call permission", tx.Input.Address)
}
}
// pubKey should be present in either "inAcc" or "tx.Input"
if err := checkInputPubKey(inAcc, tx.Input); err != nil {
log.Info(Fmt("Can't find pubkey for %X", tx.Input.Address))
return err
}
signBytes := acm.SignBytes(_s.ChainID, tx)
err := validateInput(inAcc, signBytes, tx.Input)
if err != nil {
log.Info(Fmt("validateInput failed on %X: %v", tx.Input.Address, err))
return err
}
if tx.Input.Amount < tx.Fee {
log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address))
return types.ErrTxInsufficientFunds
}
if !createContract {
//.........这里部分代码省略.........
开发者ID:huangjiehua,项目名称:tendermint,代码行数:101,代码来源:execution.go
示例5: ExecTx
// If the tx is invalid, an error will be returned.
// Unlike ExecBlock(), state will not be altered.
func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Fireable) error {
// TODO: do something with fees
fees := uint64(0)
_s := blockCache.State() // hack to access validators and event switch.
// Exec tx
switch tx := tx_.(type) {
case *types.SendTx:
accounts, err := getOrMakeAccounts(blockCache, tx.Inputs, tx.Outputs)
if err != nil {
return err
}
signBytes := account.SignBytes(tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil {
return err
}
outTotal, err := validateOutputs(tx.Outputs)
if err != nil {
return err
}
if outTotal > inTotal {
return types.ErrTxInsufficientFunds
}
fee := inTotal - outTotal
fees += fee
// Good! Adjust accounts
adjustByInputs(accounts, tx.Inputs)
adjustByOutputs(accounts, tx.Outputs)
for _, acc := range accounts {
blockCache.UpdateAccount(acc)
}
// if the evc is nil, nothing will happen
if evc != nil {
for _, i := range tx.Inputs {
evc.FireEvent(types.EventStringAccInput(i.Address), tx)
}
for _, o := range tx.Outputs {
evc.FireEvent(types.EventStringAccOutput(o.Address), tx)
}
}
return nil
case *types.CallTx:
var inAcc, outAcc *account.Account
// Validate input
inAcc = blockCache.GetAccount(tx.Input.Address)
if inAcc == nil {
log.Debug(Fmt("Can't find in account %X", tx.Input.Address))
return types.ErrTxInvalidAddress
}
// pubKey should be present in either "inAcc" or "tx.Input"
if err := checkInputPubKey(inAcc, tx.Input); err != nil {
log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address))
return err
}
signBytes := account.SignBytes(tx)
err := validateInput(inAcc, signBytes, tx.Input)
if err != nil {
log.Debug(Fmt("validateInput failed on %X:", tx.Input.Address))
return err
}
if tx.Input.Amount < tx.Fee {
log.Debug(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address))
return types.ErrTxInsufficientFunds
}
createAccount := len(tx.Address) == 0
if !createAccount {
// Validate output
if len(tx.Address) != 20 {
log.Debug(Fmt("Destination address is not 20 bytes %X", tx.Address))
return types.ErrTxInvalidAddress
}
// this may be nil if we are still in mempool and contract was created in same block as this tx
// but that's fine, because the account will be created properly when the create tx runs in the block
// and then this won't return nil. otherwise, we take their fee
outAcc = blockCache.GetAccount(tx.Address)
}
log.Debug(Fmt("Out account: %v", outAcc))
// Good!
value := tx.Input.Amount - tx.Fee
inAcc.Sequence += 1
if runCall {
var (
gas uint64 = tx.GasLimit
err error = nil
caller *vm.Account = toVMAccount(inAcc)
callee *vm.Account = nil
//.........这里部分代码省略.........
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:101,代码来源:execution.go
注:本文中的github.com/tendermint/tendermint/account.Account类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论