OSDN Git Service

Add
[bytom/vapor.git] / account / builder.go
index 143ad24..48bc807 100644 (file)
@@ -2,25 +2,26 @@ package account
 
 import (
        "context"
+       "crypto/rand"
        stdjson "encoding/json"
 
-       "github.com/vapor/blockchain/signers"
-       "github.com/vapor/blockchain/txbuilder"
-       "github.com/vapor/common"
-       "github.com/vapor/consensus"
-       "github.com/vapor/crypto/ed25519/chainkd"
-       "github.com/vapor/encoding/json"
-       "github.com/vapor/errors"
-       "github.com/vapor/protocol/bc"
-       "github.com/vapor/protocol/bc/types"
-       "github.com/vapor/protocol/vm/vmutil"
+       "github.com/bytom/vapor/blockchain/signers"
+       "github.com/bytom/vapor/blockchain/txbuilder"
+       "github.com/bytom/vapor/common"
+       "github.com/bytom/vapor/consensus"
+       "github.com/bytom/vapor/crypto/ed25519/chainkd"
+       "github.com/bytom/vapor/encoding/json"
+       "github.com/bytom/vapor/errors"
+       "github.com/bytom/vapor/protocol/bc"
+       "github.com/bytom/vapor/protocol/bc/types"
+       "github.com/bytom/vapor/protocol/vm/vmutil"
 )
 
 var (
        //chainTxUtxoNum maximum utxo quantity in a tx
-       chainTxUtxoNum = 5
+       chainTxUtxoNum = 20
        //chainTxMergeGas chain tx gas
-       chainTxMergeGas = uint64(10000000)
+       chainTxMergeGas = uint64(0)
 )
 
 //DecodeSpendAction unmarshal JSON-encoded data of spend action
@@ -456,3 +457,40 @@ func (a *vetoAction) Build(ctx context.Context, b *txbuilder.TemplateBuilder) er
        }
        return nil
 }
+
+func (m *Manager) DecodeCrossInAction(data []byte) (txbuilder.Action, error) {
+       a := &crossInAction{accounts: m}
+       err := stdjson.Unmarshal(data, a)
+       return a, err
+}
+
+type crossInAction struct {
+       accounts *Manager
+       bc.AssetAmount
+}
+
+func (a *crossInAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
+       if a.AssetId.IsZero() {
+               return txbuilder.MissingFieldsError("asset_id")
+       }
+
+       asset, err := a.accounts.store.GetAssetByID(a.AssetId)
+       if err != nil {
+               return err
+       }
+
+       var nonce [32]byte
+       if _, err := rand.Read(nonce[:]); err != nil {
+               return err
+       }
+
+       txin := types.NewCrossChainInput(nil, bc.NewHash(nonce), *a.AssetId, a.Amount, 1, asset.VMVersion, asset.RawDefinitionByte, asset.IssuanceProgram)
+       tplIn := &txbuilder.SigningInstruction{}
+       path := signers.GetBip0032Path(asset.Signer, signers.AssetKeySpace)
+       tplIn.AddRawWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
+       return builder.AddInput(txin, tplIn)
+}
+
+func (a *crossInAction) ActionType() string {
+       return "cross_chain_in"
+}
\ No newline at end of file