本文整理匯總了Golang中github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/account.SignBytes函數的典型用法代碼示例。如果您正苦於以下問題:Golang SignBytes函數的具體用法?Golang SignBytes怎麽用?Golang SignBytes使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SignBytes函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetProposal
func (cs *ConsensusState) SetProposal(proposal *types.Proposal) error {
cs.mtx.Lock()
defer cs.mtx.Unlock()
// Already have one
if cs.Proposal != nil {
return nil
}
// Does not apply
if proposal.Height != cs.Height || proposal.Round != cs.Round {
return nil
}
// We don't care about the proposal if we're already in RoundStepCommit.
if RoundStepCommit <= cs.Step {
return nil
}
// Verify POLRound, which must be -1 or between 0 and proposal.Round exclusive.
if proposal.POLRound != -1 &&
(proposal.POLRound < 0 || proposal.Round <= proposal.POLRound) {
return ErrInvalidProposalPOLRound
}
// Verify signature
if !cs.Validators.Proposer().PubKey.VerifyBytes(acm.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
return ErrInvalidProposalSignature
}
cs.Proposal = proposal
cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockPartsHeader)
return nil
}
示例2: SignVote
func (privVal *PrivValidator) SignVote(chainID string, vote *Vote) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
// If height regression, panic
if privVal.LastHeight > vote.Height {
return errors.New("Height regression in SignVote")
}
// More cases for when the height matches
if privVal.LastHeight == vote.Height {
// If round regression, panic
if privVal.LastRound > vote.Round {
return errors.New("Round regression in SignVote")
}
// If step regression, panic
if privVal.LastRound == vote.Round && privVal.LastStep > voteToStep(vote) {
return errors.New("Step regression in SignVote")
}
}
// Persist height/round/step
privVal.LastHeight = vote.Height
privVal.LastRound = vote.Round
privVal.LastStep = voteToStep(vote)
privVal.save()
// Sign
vote.Signature = privVal.signer.Sign(acm.SignBytes(chainID, vote))
return nil
}
示例3: TestSendTxSignable
func TestSendTxSignable(t *testing.T) {
sendTx := &SendTx{
Inputs: []*TxInput{
&TxInput{
Address: []byte("input1"),
Amount: 12345,
Sequence: 67890,
},
&TxInput{
Address: []byte("input2"),
Amount: 111,
Sequence: 222,
},
},
Outputs: []*TxOutput{
&TxOutput{
Address: []byte("output1"),
Amount: 333,
},
&TxOutput{
Address: []byte("output2"),
Amount: 444,
},
},
}
signBytes := acm.SignBytes(chainID, sendTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("chain_id"))
if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
}
}
示例4: TestDupeoutTxSignable
func TestDupeoutTxSignable(t *testing.T) {
privAcc := acm.GenPrivAccount()
partSetHeader := PartSetHeader{Total: 10, Hash: []byte("partsethash")}
voteA := &Vote{
Height: 10,
Round: 2,
Type: VoteTypePrevote,
BlockHash: []byte("myblockhash"),
BlockPartsHeader: partSetHeader,
}
sig := privAcc.Sign(chainID, voteA)
voteA.Signature = sig.(acm.SignatureEd25519)
voteB := voteA.Copy()
voteB.BlockHash = []byte("myotherblockhash")
sig = privAcc.Sign(chainID, voteB)
voteB.Signature = sig.(acm.SignatureEd25519)
dupeoutTx := &DupeoutTx{
Address: []byte("address1"),
VoteA: *voteA,
VoteB: *voteB,
}
signBytes := acm.SignBytes(chainID, dupeoutTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[20,{"address":"6164647265737331","vote_a":%v,"vote_b":%v}]}`,
config.GetString("chain_id"), *voteA, *voteB)
if signStr != expected {
t.Errorf("Got unexpected sign string for DupeoutTx")
}
}
示例5: Hash
func (data *Data) Hash() []byte {
if data.hash == nil {
bs := make([]interface{}, len(data.Txs))
for i, tx := range data.Txs {
bs[i] = acm.SignBytes(config.GetString("chain_id"), tx)
}
data.hash = merkle.SimpleHashFromBinaries(bs) // NOTE: leaves are TxIDs.
}
return data.hash
}
示例6: TestRebondTxSignable
func TestRebondTxSignable(t *testing.T) {
rebondTx := &RebondTx{
Address: []byte("address1"),
Height: 111,
}
signBytes := acm.SignBytes(chainID, rebondTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[19,{"address":"6164647265737331","height":111}]}`,
config.GetString("chain_id"))
if signStr != expected {
t.Errorf("Got unexpected sign string for RebondTx")
}
}
示例7: VerifyValidation
// Verify that +2/3 of the set had signed the given signBytes
func (valSet *ValidatorSet) VerifyValidation(chainID string,
hash []byte, parts types.PartSetHeader, height int, v *types.Validation) error {
if valSet.Size() != len(v.Precommits) {
return fmt.Errorf("Invalid validation -- wrong set size: %v vs %v", valSet.Size(), len(v.Precommits))
}
if height != v.Height() {
return fmt.Errorf("Invalid validation -- wrong height: %v vs %v", height, v.Height())
}
talliedVotingPower := int64(0)
round := v.Round()
for idx, precommit := range v.Precommits {
// may be nil if validator skipped.
if precommit == nil {
continue
}
if precommit.Height != height {
return fmt.Errorf("Invalid validation -- wrong height: %v vs %v", height, precommit.Height)
}
if precommit.Round != round {
return fmt.Errorf("Invalid validation -- wrong round: %v vs %v", round, precommit.Round)
}
if precommit.Type != types.VoteTypePrecommit {
return fmt.Errorf("Invalid validation -- not precommit @ index %v", idx)
}
_, val := valSet.GetByIndex(idx)
// Validate signature
precommitSignBytes := account.SignBytes(chainID, precommit)
if !val.PubKey.VerifyBytes(precommitSignBytes, precommit.Signature) {
return fmt.Errorf("Invalid validation -- invalid signature: %v", precommit)
}
if !bytes.Equal(precommit.BlockHash, hash) {
continue // Not an error, but doesn't count
}
if !parts.Equals(precommit.BlockParts) {
continue // Not an error, but doesn't count
}
// Good precommit!
talliedVotingPower += val.VotingPower
}
if talliedVotingPower > valSet.TotalVotingPower()*2/3 {
return nil
} else {
return fmt.Errorf("Invalid validation -- insufficient voting power: got %v, needed %v",
talliedVotingPower, (valSet.TotalVotingPower()*2/3 + 1))
}
}
示例8: TestProposalSignable
func TestProposalSignable(t *testing.T) {
proposal := &Proposal{
Height: 12345,
Round: 23456,
BlockPartsHeader: PartSetHeader{111, []byte("blockparts")},
POLRound: -1,
}
signBytes := acm.SignBytes(config.GetString("chain_id"), proposal)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_round":-1,"round":23456}}`,
config.GetString("chain_id"))
if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
}
}
示例9: addVote
func (voteSet *VoteSet) addVote(val *sm.Validator, valIndex int, vote *types.Vote) (bool, int, error) {
// Make sure the step matches. (or that vote is commit && round < voteSet.round)
if (vote.Height != voteSet.height) ||
(vote.Round != voteSet.round) ||
(vote.Type != voteSet.type_) {
return false, 0, types.ErrVoteUnexpectedStep
}
// Check signature.
if !val.PubKey.VerifyBytes(acm.SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
// Bad signature.
return false, 0, types.ErrVoteInvalidSignature
}
// If vote already exists, return false.
if existingVote := voteSet.votes[valIndex]; existingVote != nil {
if bytes.Equal(existingVote.BlockHash, vote.BlockHash) {
return false, valIndex, nil
} else {
return false, valIndex, &types.ErrVoteConflictingSignature{
VoteA: existingVote,
VoteB: vote,
}
}
}
// Add vote.
voteSet.votes[valIndex] = vote
voteSet.votesBitArray.SetIndex(valIndex, true)
blockKey := string(vote.BlockHash) + string(wire.BinaryBytes(vote.BlockParts))
totalBlockHashVotes := voteSet.votesByBlock[blockKey] + val.VotingPower
voteSet.votesByBlock[blockKey] = totalBlockHashVotes
voteSet.totalVotes += val.VotingPower
// If we just nudged it up to two thirds majority, add it.
if totalBlockHashVotes > voteSet.valSet.TotalVotingPower()*2/3 &&
(totalBlockHashVotes-val.VotingPower) <= voteSet.valSet.TotalVotingPower()*2/3 {
voteSet.maj23Hash = vote.BlockHash
voteSet.maj23Parts = vote.BlockParts
voteSet.maj23Exists = true
}
return true, valIndex, nil
}
示例10: checkTx
func checkTx(t *testing.T, fromAddr []byte, priv *acm.PrivAccount, tx *types.SendTx) {
if bytes.Compare(tx.Inputs[0].Address, fromAddr) != 0 {
t.Fatal("Tx input addresses don't match!")
}
signBytes := acm.SignBytes(chainID, tx)
in := tx.Inputs[0] //(*types.SendTx).Inputs[0]
if err := in.ValidateBasic(); err != nil {
t.Fatal(err)
}
// Check signatures
// acc := getAccount(t, byteAddr)
// NOTE: using the acc here instead of the in fails; it is nil.
if !in.PubKey.VerifyBytes(signBytes, in.Signature) {
t.Fatal(types.ErrTxInvalidSignature)
}
}
示例11: TestNameTxSignable
func TestNameTxSignable(t *testing.T) {
nameTx := &NameTx{
Input: &TxInput{
Address: []byte("input1"),
Amount: 12345,
Sequence: 250,
},
Name: "google.com",
Data: "secretly.not.google.com",
Fee: 1000,
}
signBytes := acm.SignBytes(chainID, nameTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[3,{"data":"secretly.not.google.com","fee":1000,"input":{"address":"696E70757431","amount":12345,"sequence":250},"name":"google.com"}]}`,
config.GetString("chain_id"))
if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
}
}
示例12: SignRebondTx
func (privVal *PrivValidator) SignRebondTx(chainID string, rebondTx *types.RebondTx) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
if privVal.LastHeight < rebondTx.Height {
// Persist height/round/step
// Prevent doing anything else for this rebondTx.Height.
privVal.LastHeight = rebondTx.Height
privVal.LastRound = math.MaxInt32 // MaxInt64 overflows on 32bit architectures.
privVal.LastStep = math.MaxInt8
privVal.save()
// Sign
rebondTx.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, rebondTx)).(account.SignatureEd25519)
return nil
} else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of rebondTx: Height %v", rebondTx.Height))
}
}
示例13: TestCallTxSignable
func TestCallTxSignable(t *testing.T) {
callTx := &CallTx{
Input: &TxInput{
Address: []byte("input1"),
Amount: 12345,
Sequence: 67890,
},
Address: []byte("contract1"),
GasLimit: 111,
Fee: 222,
Data: []byte("data1"),
}
signBytes := acm.SignBytes(chainID, callTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
config.GetString("chain_id"))
if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
}
}
示例14: SignProposal
func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
if privVal.LastHeight < proposal.Height ||
privVal.LastHeight == proposal.Height && privVal.LastRound < proposal.Round ||
privVal.LastHeight == 0 && privVal.LastRound == 0 && privVal.LastStep == stepNone {
// Persist height/round/step
privVal.LastHeight = proposal.Height
privVal.LastRound = proposal.Round
privVal.LastStep = stepPropose
privVal.save()
// Sign
proposal.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, proposal)).(account.SignatureEd25519)
return nil
} else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of proposal: Height %v, Round %v", proposal.Height, proposal.Round))
}
}
示例15: TestPermissionsTxSignable
func TestPermissionsTxSignable(t *testing.T) {
permsTx := &PermissionsTx{
Input: &TxInput{
Address: []byte("input1"),
Amount: 12345,
Sequence: 250,
},
PermArgs: &ptypes.SetBaseArgs{
Address: []byte("address1"),
Permission: 1,
Value: true,
},
}
signBytes := acm.SignBytes(chainID, permsTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[32,{"args":"[2,{"address":"6164647265737331","permission":1,"value":true}]","input":{"address":"696E70757431","amount":12345,"sequence":250}}]}`,
config.GetString("chain_id"))
if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
}
}