OSDN Git Service

Add vote reward memo (#381)
[bytom/vapor.git] / toolbar / vote_reward / settlementvotereward / settlementreward.go
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
 }