OSDN Git Service

fix log
[bytom/vapor.git] / account / builder.go
index 027e1fb..ca533a0 100644 (file)
@@ -18,7 +18,7 @@ import (
 
 var (
        //chainTxUtxoNum maximum utxo quantity in a tx
-       chainTxUtxoNum = 5
+       chainTxUtxoNum = 20
        //chainTxMergeGas chain tx gas
        chainTxMergeGas = uint64(10000000)
 )
@@ -90,7 +90,7 @@ func (m *Manager) reserveBtmUtxoChain(builder *txbuilder.TemplateBuilder, accoun
        return utxos, nil
 }
 
-func (m *Manager) buildBtmTxChain(utxos []*UTXO, signer *signers.Signer) ([]*txbuilder.Template, *UTXO, error) {
+func (m *Manager) BuildBtmTxChain(utxos []*UTXO, signer *signers.Signer) ([]*txbuilder.Template, *UTXO, error) {
        if len(utxos) == 0 {
                return nil, nil, errors.New("mergeSpendActionUTXO utxos num 0")
        }
@@ -166,6 +166,7 @@ func SpendAccountChain(ctx context.Context, builder *txbuilder.TemplateBuilder,
        if !ok {
                return nil, errors.New("fail to convert the spend action")
        }
+
        if *act.AssetId != *consensus.BTMAssetID {
                return nil, errors.New("spend chain action only support BTM")
        }
@@ -180,7 +181,7 @@ func SpendAccountChain(ctx context.Context, builder *txbuilder.TemplateBuilder,
                return nil, err
        }
 
-       tpls, utxo, err := act.accounts.buildBtmTxChain(utxos, acct.Signer)
+       tpls, utxo, err := act.accounts.BuildBtmTxChain(utxos, acct.Signer)
        if err != nil {
                return nil, err
        }
@@ -309,7 +310,12 @@ func (a *spendUTXOAction) Build(ctx context.Context, b *txbuilder.TemplateBuilde
 
 // UtxoToInputs convert an utxo to the txinput
 func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.SigningInstruction, error) {
-       txInput := types.NewSpendInput(nil, u.SourceID, u.AssetID, u.Amount, u.SourcePos, u.ControlProgram)
+       txInput := &types.TxInput{}
+       if u.Vote == nil {
+               txInput = types.NewSpendInput(nil, u.SourceID, u.AssetID, u.Amount, u.SourcePos, u.ControlProgram)
+       } else {
+               txInput = types.NewVetoInput(nil, u.SourceID, u.AssetID, u.Amount, u.SourcePos, u.ControlProgram, u.Vote)
+       }
        sigInst := &txbuilder.SigningInstruction{}
        if signer == nil {
                return txInput, sigInst, nil
@@ -319,6 +325,7 @@ func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.S
        if err != nil {
                return nil, nil, err
        }
+
        if u.Address == "" {
                sigInst.AddWitnessKeys(signer.XPubs, path, signer.Quorum)
                return txInput, sigInst, nil
@@ -377,17 +384,18 @@ func (m *Manager) insertControlProgramDelayed(b *txbuilder.TemplateBuilder, acp
                if len(acps) == 0 {
                        return nil
                }
+
                return m.SaveControlPrograms(acps...)
        })
 }
 
-//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"`
@@ -395,11 +403,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")