當前位置: 首頁>>代碼示例>>Golang>>正文


Golang account.Account類代碼示例

本文整理匯總了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;未經允許,請勿轉載。