当前位置: 首页>>代码示例>>Golang>>正文


Golang account.PrivAccount类代码示例

本文整理汇总了Golang中github.com/tendermint/tendermint/account.PrivAccount的典型用法代码示例。如果您正苦于以下问题:Golang PrivAccount类的具体用法?Golang PrivAccount怎么用?Golang PrivAccount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PrivAccount类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SignInput

func (tx *SendTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error {
	if i >= len(tx.Inputs) {
		return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs))
	}
	tx.Inputs[i].PubKey = privAccount.PubKey
	tx.Inputs[i].Signature = privAccount.Sign(chainID, tx)
	return nil
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:8,代码来源:tx_utils.go

示例2: SignBond

func (tx *BondTx) SignBond(chainID string, privAccount *acm.PrivAccount) error {
	sig := privAccount.Sign(chainID, tx)
	sigEd, ok := sig.(acm.SignatureEd25519)
	if !ok {
		return fmt.Errorf("Bond signer must be ED25519")
	}
	tx.Signature = sigEd
	return nil
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:9,代码来源:tx_utils.go

示例3: Sign

func (tx *CallTx) Sign(chainID string, privAccount *acm.PrivAccount) {
	tx.Input.PubKey = privAccount.PubKey
	tx.Input.Signature = privAccount.Sign(chainID, tx)
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:4,代码来源:tx_utils.go

示例4: send_tx

func send_tx() {

	// Get PrivAccount
	var privAccount *acm.PrivAccount
	secret := getString("Enter your secret, or just hit <Enter> to enter a private key in HEX.\n> ")
	if secret == "" {
		privKeyBytes := getByteSliceFromHex("Enter your private key in HEX (e.g. E353CAD81134A301A542AEBE2D2E4EF1A64A145117EC72743AE9C9D171A4AA69F3A7DD670A9E9307AAED000D97D5B3C07D90276BFCEEDA5ED11DA089A4E87A81):\n> ")
		privAccount = acm.GenPrivAccountFromPrivKeyBytes(privKeyBytes)
	} else {
		// Auto-detect private key hex
		if len(secret) == 128 {
			privKeyBytes, err := hex.DecodeString(secret)
			if err == nil {
				fmt.Println("Detected priv-key bytes...")
				privAccount = acm.GenPrivAccountFromPrivKeyBytes(privKeyBytes)
			} else {
				fmt.Println("That's a long seed...")
				privAccount = acm.GenPrivAccountFromSecret(secret)
			}
		} else {
			privAccount = acm.GenPrivAccountFromSecret(secret)
		}
	}
	pubKey := privAccount.PubKey

	// Get account data
	cli := cclient.NewClient("http://localhost:46657", "JSONRPC")
	res, err := cli.GetAccount(privAccount.Address)
	if err != nil {
		Exit(Fmt("Error fetching account: %v", err))
	}
	if res == nil {
		Exit(Fmt("No account was found with that secret/private-key"))
	}
	inputAcc := res.Account
	fmt.Printf(`
Source account:
Address:     %X
PubKey:      %v
Sequence:    %v
Balance:     %v
Permissions: %v
`,
		inputAcc.Address,
		pubKey,
		inputAcc.Sequence,
		inputAcc.Balance,
		inputAcc.Permissions)

	output := getByteSliceFromHex("\nEnter the output address in HEX:\n> ")
	amount := getInt64("Enter the amount to send:\n> ")

	// Construct transaction
	tx := types.NewSendTx()
	tx.AddInputWithNonce(pubKey, amount, inputAcc.Sequence+1)
	tx.AddOutput(output, amount)
	tx.Inputs[0].Signature = privAccount.Sign(config.GetString("chain_id"), tx)
	fmt.Println("Signed SendTx!: ", tx)

	// Sign up for events
	wsCli := cclient.NewWSClient("ws://localhost:46657/websocket")
	wsCli.Start()
	err = wsCli.Subscribe(types.EventStringAccInput(inputAcc.Address))
	if err != nil {
		Exit(Fmt("Error subscribing to account send event: %v", err))
	}

	// Broadcast transaction
	_, err = cli.BroadcastTx(tx)
	if err != nil {
		Exit(Fmt("Error broadcasting transaction: %v", err))
	}
	fmt.Println("Waiting for confirmation...")

	_ = <-wsCli.EventsCh
	fmt.Println("Confirmed.")
}
开发者ID:huangjiehua,项目名称:tendermint,代码行数:77,代码来源:send_tx.go


注:本文中的github.com/tendermint/tendermint/account.PrivAccount类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。