})
}
-//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"`
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")
"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
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
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
}
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
}
}
}
-func TestSerializationUnvote(t *testing.T) {
+func TestSerializationVeto(t *testing.T) {
arguments := [][]byte{
[]byte("arguments1"),
[]byte("arguments2"),
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
"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
}
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
}
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
}
}