From: wz Date: Wed, 19 Jun 2019 05:40:32 +0000 (+0800) Subject: rename unvote to veto (#191) X-Git-Tag: v1.0.5~208^2~10 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=f578f565b46c85e08256c089a9068ee390105048 rename unvote to veto (#191) --- diff --git a/account/builder.go b/account/builder.go index fe96d747..5f2448a7 100644 --- a/account/builder.go +++ b/account/builder.go @@ -386,13 +386,13 @@ func (m *Manager) insertControlProgramDelayed(b *txbuilder.TemplateBuilder, acp }) } -//DecodeUnvoteAction unmarshal JSON-encoded data of spend action -func (m *Manager) DecodeUnvoteAction(data []byte) (txbuilder.Action, error) { - a := &unvoteAction{accounts: m} +//DecodeVetoAction unmarshal JSON-encoded data of spend action +func (m *Manager) DecodeVetoAction(data []byte) (txbuilder.Action, error) { + a := &vetoAction{accounts: m} return a, stdjson.Unmarshal(data, a) } -type unvoteAction struct { +type vetoAction struct { accounts *Manager bc.AssetAmount AccountID string `json:"account_id"` @@ -400,11 +400,11 @@ type unvoteAction struct { UseUnconfirmed bool `json:"use_unconfirmed"` } -func (a *unvoteAction) ActionType() string { - return "unvote" +func (a *vetoAction) ActionType() string { + return "veto" } -func (a *unvoteAction) Build(ctx context.Context, b *txbuilder.TemplateBuilder) error { +func (a *vetoAction) Build(ctx context.Context, b *txbuilder.TemplateBuilder) error { var missing []string if a.AccountID == "" { missing = append(missing, "account_id") diff --git a/api/transact.go b/api/transact.go index 3f2c0db5..76e6d537 100644 --- a/api/transact.go +++ b/api/transact.go @@ -31,7 +31,7 @@ func (a *API) actionDecoder(action string) (func([]byte) (txbuilder.Action, erro "cross_chain_in": txbuilder.DecodeCrossInAction, "spend_account": a.wallet.AccountMgr.DecodeSpendAction, "spend_account_unspent_output": a.wallet.AccountMgr.DecodeSpendUTXOAction, - "unvote": a.wallet.AccountMgr.DecodeUnvoteAction, + "veto": a.wallet.AccountMgr.DecodeVetoAction, } decoder, ok := decoders[action] return decoder, ok diff --git a/docs/vote/read.md b/docs/vote/read.md index 4c97af68..2783be2b 100644 --- a/docs/vote/read.md +++ b/docs/vote/read.md @@ -35,13 +35,13 @@ curl -X POST http://ip:port/build-transaction -d '{"base_transaction":null,"acti Example ```shell -curl -X POST http://ip:port/build-transaction -d '{"base_transaction":null,"actions":[{"account_id":"0BF63M2U00A04","amount":20000000,"asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","type":"spend_account"},{"account_id":"0BF63M2U00A04","amount":99,"asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","vote":"af594006a40837d9f028daabb6d589df0b9138daefad5683e5233c2646279217294a8d532e60863bcf196625a35fb8ceeffa3c09610eb92dcfb655a947f13269","type":"unvote"},{"amount":99,"asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","address":"bm1q50u3z8empm5ke0g3ngl2t3sqtr6sd7cepd3z68","type":"control_address"}],"ttl":0,"time_range": 43432}' +curl -X POST http://ip:port/build-transaction -d '{"base_transaction":null,"actions":[{"account_id":"0BF63M2U00A04","amount":20000000,"asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","type":"spend_account"},{"account_id":"0BF63M2U00A04","amount":99,"asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","vote":"af594006a40837d9f028daabb6d589df0b9138daefad5683e5233c2646279217294a8d532e60863bcf196625a35fb8ceeffa3c09610eb92dcfb655a947f13269","type":"veto"},{"amount":99,"asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","address":"bm1q50u3z8empm5ke0g3ngl2t3sqtr6sd7cepd3z68","type":"control_address"}],"ttl":0,"time_range": 43432}' ``` 以上实例中: 第一个action的type:spend_account 是手续费 -第二个action的type:unvote 取消投票,vote 被取消投票的公钥 +第二个action的type:veto 取消投票,vote 被取消投票的公钥 第三个action的type:control_address 还是以前的输出 \ No newline at end of file diff --git a/protocol/bc/types/txinput.go b/protocol/bc/types/txinput.go index 49188415..888c9420 100644 --- a/protocol/bc/types/txinput.go +++ b/protocol/bc/types/txinput.go @@ -180,7 +180,7 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { case VetoInputType: ui := new(VetoInput) t.TypedInput = ui - if ui.UnvoteCommitmentSuffix, err = ui.SpendCommitment.readFrom(r, 1); err != nil { + if ui.VetoCommitmentSuffix, err = ui.SpendCommitment.readFrom(r, 1); err != nil { return err } @@ -286,7 +286,7 @@ func (t *TxInput) writeInputCommitment(w io.Writer) (err error) { if _, err = w.Write([]byte{VetoInputType}); err != nil { return err } - return inp.SpendCommitment.writeExtensibleString(w, inp.UnvoteCommitmentSuffix, t.AssetVersion) + return inp.SpendCommitment.writeExtensibleString(w, inp.VetoCommitmentSuffix, t.AssetVersion) } return nil } diff --git a/protocol/bc/types/txinput_test.go b/protocol/bc/types/txinput_test.go index 419b3cd8..c590ce6d 100644 --- a/protocol/bc/types/txinput_test.go +++ b/protocol/bc/types/txinput_test.go @@ -125,7 +125,7 @@ func TestSerializationCrossIn(t *testing.T) { } } -func TestSerializationUnvote(t *testing.T) { +func TestSerializationVeto(t *testing.T) { arguments := [][]byte{ []byte("arguments1"), []byte("arguments2"), @@ -136,15 +136,15 @@ func TestSerializationUnvote(t *testing.T) { wantHex := strings.Join([]string{ "01", // asset version "54", // input commitment length - "03", // unvote type flag - "52", // unvote commitment length + "03", // veto type flag + "52", // veto commitment length "fad5195a0c8e3b590b86a3c0a95e7529565888508aecca96e9aeda633002f409", // source id "fe9791d71b67ee62515e08723c061b5ccb952a80d804417c8aeedf7f633c524a", // assetID "92c30f", // amount "03", // source position "01", // vm version - "0c", // unvote program length - "7370656e6450726f6772616d", // unvote program + "0c", // veto program length + "7370656e6450726f6772616d", // veto program "9901", // witness length "02", // argument array length "0a", // first argument length diff --git a/protocol/bc/types/veto_input.go b/protocol/bc/types/veto_input.go index 59517bd7..548310fa 100644 --- a/protocol/bc/types/veto_input.go +++ b/protocol/bc/types/veto_input.go @@ -4,11 +4,11 @@ import ( "github.com/vapor/protocol/bc" ) -// VetoInput satisfies the TypedInput interface and represents a unvote transaction. +// VetoInput satisfies the TypedInput interface and represents a veto transaction. type VetoInput struct { - UnvoteCommitmentSuffix []byte // The unconsumed suffix of the output commitment - Arguments [][]byte // Witness - Vote []byte // voter xpub + VetoCommitmentSuffix []byte // The unconsumed suffix of the output commitment + Arguments [][]byte // Witness + Vote []byte // voter xpub SpendCommitment } diff --git a/protocol/state/vote_result.go b/protocol/state/vote_result.go index 96ae36ff..6a434c8d 100644 --- a/protocol/state/vote_result.go +++ b/protocol/state/vote_result.go @@ -58,13 +58,13 @@ func (v *VoteResult) ApplyBlock(block *types.Block) error { for _, tx := range block.Transactions { for _, input := range tx.Inputs { - unVoteInput, ok := input.TypedInput.(*types.VetoInput) + vetoInput, ok := input.TypedInput.(*types.VetoInput) if !ok { continue } - pubkey := hex.EncodeToString(unVoteInput.Vote) - v.NumOfVote[pubkey], ok = checked.SubUint64(v.NumOfVote[pubkey], unVoteInput.Amount) + pubkey := hex.EncodeToString(vetoInput.Vote) + v.NumOfVote[pubkey], ok = checked.SubUint64(v.NumOfVote[pubkey], vetoInput.Amount) if !ok { return errVotingOperationOverFlow } @@ -136,13 +136,13 @@ func (v *VoteResult) DetachBlock(block *types.Block) error { for i := len(block.Transactions) - 1; i >= 0; i-- { tx := block.Transactions[i] for _, input := range tx.Inputs { - unVoteInput, ok := input.TypedInput.(*types.VetoInput) + vetoInput, ok := input.TypedInput.(*types.VetoInput) if !ok { continue } - pubkey := hex.EncodeToString(unVoteInput.Vote) - if v.NumOfVote[pubkey], ok = checked.AddUint64(v.NumOfVote[pubkey], unVoteInput.Amount); !ok { + pubkey := hex.EncodeToString(vetoInput.Vote) + if v.NumOfVote[pubkey], ok = checked.AddUint64(v.NumOfVote[pubkey], vetoInput.Amount); !ok { return errVotingOperationOverFlow } }