OSDN Git Service

add vote reward memo
authorpaladz <453256728@qq.com>
Mon, 12 Aug 2019 05:47:06 +0000 (13:47 +0800)
committerpaladz <453256728@qq.com>
Mon, 12 Aug 2019 05:47:06 +0000 (13:47 +0800)
toolbar/apinode/transaction.go
toolbar/consensusreward/consensus_reward.go
toolbar/vote_reward/settlementvotereward/settlementreward.go

index 5220889..682b6ed 100644 (file)
@@ -1,6 +1,7 @@
 package apinode
 
 import (
+       "encoding/hex"
        "encoding/json"
 
        "github.com/vapor/blockchain/txbuilder"
@@ -44,9 +45,33 @@ func (c *ControlAddressAction) MarshalJSON() ([]byte, error) {
        })
 }
 
-func (n *Node) BatchSendBTM(accountID, password string, outputs map[string]uint64) (string, error) {
+type RetireAction struct {
+       *bc.AssetAmount
+       Arbitrary []byte
+}
+
+func (r *RetireAction) MarshalJSON() ([]byte, error) {
+       return json.Marshal(&struct {
+               Type      string `json:"type"`
+               Arbitrary string `json:"arbitrary"`
+               *bc.AssetAmount
+       }{
+               Type:        "retire",
+               Arbitrary:   hex.EncodeToString(r.Arbitrary),
+               AssetAmount: r.AssetAmount,
+       })
+}
+
+func (n *Node) BatchSendBTM(accountID, password string, outputs map[string]uint64, memo []byte) (string, error) {
        totalBTM := uint64(1000000)
        actions := []interface{}{}
+       if len(memo) > 0 {
+               actions = append(actions, &RetireAction{
+                       Arbitrary:   memo,
+                       AssetAmount: &bc.AssetAmount{AssetId: consensus.BTMAssetID, Amount: 1},
+               })
+       }
+
        for address, amount := range outputs {
                actions = append(actions, &ControlAddressAction{
                        Address:     address,
index 8e3de02..6650563 100644 (file)
@@ -71,7 +71,7 @@ func (s *StandbyNodeReward) Settlement() error {
                return nil
        }
 
-       txID, err := s.node.BatchSendBTM(s.cfg.RewardConf.AccountID, s.cfg.RewardConf.Password, rewards)
+       txID, err := s.node.BatchSendBTM(s.cfg.RewardConf.AccountID, s.cfg.RewardConf.Password, rewards, nil)
        if err == nil {
                log.WithFields(log.Fields{
                        "tx_hash":      txID,
index e110b95..a6fdbcc 100644 (file)
@@ -2,6 +2,7 @@ package settlementvotereward
 
 import (
        "bytes"
+       "encoding/json"
        "math/big"
 
        "github.com/jinzhu/gorm"
@@ -36,6 +37,13 @@ type SettlementReward struct {
        endHeight   uint64
 }
 
+type memo struct {
+       StartHeight uint64 `json:"start_height"`
+       EndHeight   uint64 `json:"end_height"`
+       NodePubkey  string `json:"node_pubkey"`
+       RewardRatio uint64 `json:"reward_ratio"`
+}
+
 func NewSettlementReward(db *gorm.DB, cfg *config.Config, startHeight, endHeight uint64) *SettlementReward {
        return &SettlementReward{
                db:          db,
@@ -85,8 +93,18 @@ func (s *SettlementReward) Settlement() error {
                return errNotRewardTx
        }
 
+       data, err := json.Marshal(&memo{
+               StartHeight: s.startHeight,
+               EndHeight:   s.endHeight,
+               NodePubkey:  s.rewardCfg.XPub,
+               RewardRatio: s.rewardCfg.RewardRatio,
+       })
+       if err != nil {
+               return err
+       }
+
        // send transactions
-       _, err := s.node.BatchSendBTM(s.rewardCfg.AccountID, s.rewardCfg.Password, s.rewards)
+       _, err = s.node.BatchSendBTM(s.rewardCfg.AccountID, s.rewardCfg.Password, s.rewards, data)
        return err
 }