OSDN Git Service

Add issue for claim
authormars <mars@bytom.io>
Mon, 15 Apr 2019 08:03:54 +0000 (16:03 +0800)
committermars <mars@bytom.io>
Mon, 15 Apr 2019 08:03:54 +0000 (16:03 +0800)
12 files changed:
claim/rpc/bytom/bytom_claim_tx.go
claim/rpc/claim_tx.go
cmd/vapor/side_chain/LOCK [deleted file]
cmd/vapor/side_chain/config.toml [deleted file]
protocol/bc/claim.go
protocol/bc/types/claim_pegin.go
protocol/bc/types/txinput.go
protocol/validation/block.go
tools/side_chain_tool/app/api/transaction.py
tools/side_chain_tool/web/cliamtx.html
wallet/indexer.go
wallet/utxo.go

index f7a13f2..86796b9 100644 (file)
@@ -162,7 +162,7 @@ func (b *BytomClaimTx) createRawPegin(ins rpc.ClaimTxParam) (*txbuilder.Template
        outputAccount := rawTx.Outputs[nOut].Amount
        assetID := *rawTx.Outputs[nOut].AssetId
 
-       txInput := types.NewClaimInput(nil, sourceID, assetID, outputAccount, uint64(nOut), cp.ControlProgram)
+       txInput := types.NewClaimInput(nil, sourceID, assetID, outputAccount, uint64(nOut), cp.ControlProgram, ins.AssetDefinition)
        if err := builder.AddInput(txInput, &txbuilder.SigningInstruction{}); err != nil {
                return nil, err
        }
@@ -327,7 +327,7 @@ func (b *BytomClaimTx) createContractRawPegin(ins rpc.ClaimTxParam) (*txbuilder.
        outputAccount := rawTx.Outputs[nOut].Amount
        assetID := *rawTx.Outputs[nOut].AssetId
 
-       txInput := types.NewClaimInput(nil, sourceID, assetID, outputAccount, uint64(nOut), cp.ControlProgram)
+       txInput := types.NewClaimInput(nil, sourceID, assetID, outputAccount, uint64(nOut), cp.ControlProgram, ins.AssetDefinition)
        if err := builder.AddInput(txInput, &txbuilder.SigningInstruction{}); err != nil {
                return nil, err
        }
@@ -374,13 +374,15 @@ func (b *BytomClaimTx) createContractRawPegin(ins rpc.ClaimTxParam) (*txbuilder.
        stack = append(stack, txOutProof)
        //      tmpl.Transaction.Inputs[0].Peginwitness = stack
        txData.Inputs[0].Peginwitness = stack
-
-       //交易费估算
-       txGasResp, err := EstimateTxGas(*tmpl)
-       if err != nil {
-               return nil, err
-       }
-       txData.Outputs[0].Amount = txData.Outputs[0].Amount - uint64(txGasResp.TotalNeu)
+       // 由于claim tx是侧链的资产的源头,故不收取交易费
+       /*
+               //交易费估算
+               txGasResp, err := EstimateTxGas(*tmpl)
+               if err != nil {
+                       return nil, err
+               }
+               txData.Outputs[0].Amount = txData.Outputs[0].Amount - uint64(txGasResp.TotalNeu)
+       */
        //重设置Transaction
        tmpl.Transaction = types.NewTx(*txData)
        return tmpl, nil
index e89113c..1091492 100644 (file)
@@ -7,14 +7,15 @@ import (
 )
 
 type ClaimTxParam struct {
-       Password     string               `json:"password"`
-       RawTx        string               `json:"raw_transaction"`
-       BlockHeader  string               `json:"block_header"`
-       TxHashes     []chainjson.HexBytes `json:"tx_hashes"`
-       StatusHashes []chainjson.HexBytes `json:"status_hashes"`
-       Flags        []uint32             `json:"flags"`
-       MatchedTxIDs []chainjson.HexBytes `json:"matched_tx_ids"`
-       ClaimScript  chainjson.HexBytes   `json:"claim_script"`
+       Password        string               `json:"password"`
+       RawTx           string               `json:"raw_transaction"`
+       BlockHeader     string               `json:"block_header"`
+       TxHashes        []chainjson.HexBytes `json:"tx_hashes"`
+       StatusHashes    []chainjson.HexBytes `json:"status_hashes"`
+       Flags           []uint32             `json:"flags"`
+       MatchedTxIDs    []chainjson.HexBytes `json:"matched_tx_ids"`
+       ClaimScript     chainjson.HexBytes   `json:"claim_script"`
+       AssetDefinition chainjson.HexBytes   `json:"asset_definition"`
 }
 
 type ClaimTx interface {
diff --git a/cmd/vapor/side_chain/LOCK b/cmd/vapor/side_chain/LOCK
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/cmd/vapor/side_chain/config.toml b/cmd/vapor/side_chain/config.toml
deleted file mode 100644 (file)
index 4ec6cb7..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# This is a TOML config file.
-# For more information, see https://github.com/toml-lang/toml
-fast_sync = true
-db_backend = "leveldb"
-api_addr = "0.0.0.0:8888"
-chain_id = "solonet"
-[p2p]
-laddr = "tcp://0.0.0.0:56658"
-seeds = "127.0.0.1:56659"
index 14baf45..679de20 100644 (file)
@@ -4,6 +4,7 @@ import "io"
 
 func (Claim) typ() string { return "claim1" }
 func (c *Claim) writeForHash(w io.Writer) {
+       mustWriteForHash(w, c.SpentOutputId)
        mustWriteForHash(w, c.Peginwitness)
 }
 
index b013205..eb8943b 100644 (file)
@@ -4,16 +4,16 @@ import (
        "github.com/vapor/protocol/bc"
 )
 
-
 // ClaimInput satisfies the TypedInput interface and represents a spend transaction.
 type ClaimInput struct {
        SpendCommitmentSuffix []byte   // The unconsumed suffix of the output commitment
        Arguments             [][]byte // Witness
+       AssetDefinition       []byte
        SpendCommitment
 }
 
 // NewClaimInput create a new SpendInput struct.
-func NewClaimInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte) *TxInput {
+func NewClaimInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte, assetDefinition []byte) *TxInput {
 
        sc := SpendCommitment{
                AssetAmount: bc.AssetAmount{
@@ -31,6 +31,7 @@ func NewClaimInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amo
                TypedInput: &ClaimInput{
                        SpendCommitment: sc,
                        Arguments:       arguments,
+                       AssetDefinition: assetDefinition,
                },
        }
 }
index 8eaafaf..95c2f5d 100644 (file)
@@ -223,6 +223,9 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
                                return err
                        }
                case *ClaimInput:
+                       if inp.AssetDefinition, err = blockchain.ReadVarstr31(r); err != nil {
+                               return err
+                       }
                        if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil {
                                return err
                        }
@@ -312,6 +315,9 @@ func (t *TxInput) writeInputWitness(w io.Writer) error {
                _, err := blockchain.WriteVarstrList(w, inp.Arguments)
                return err
        case *ClaimInput:
+               if _, err := blockchain.WriteVarstr31(w, inp.AssetDefinition); err != nil {
+                       return err
+               }
                _, err := blockchain.WriteVarstrList(w, inp.Arguments)
 
                return err
index 17aff8a..e8cccc9 100644 (file)
@@ -55,7 +55,7 @@ func checkCoinbaseAmount(b *bc.Block, amount uint64) error {
 
 // ValidateBlockHeader check the block's header
 func ValidateBlockHeader(b *bc.Block, block *types.Block, parent *state.BlockNode) error {
-       if b.Version < parent.Version {
+       if b.Version != 1 {
                return errors.WithDetailf(errVersionRegression, "previous block verson %d, current block version %d", parent.Version, b.Version)
        }
        if b.Height != parent.Height+1 {
index c7c83f1..9cc304b 100644 (file)
@@ -143,8 +143,23 @@ def claim_tx():
     else:
         return json_contents(jsonify(code=-1, msg="get raw transaction fail"))
 
+
+    # 主链获取资产描述
+    assetDefinition = ""
+    body_json = {"id": request.json['asset_id'].encode('utf-8')}
+    response = connMain.request("/get-asset",body_json)
+    resp_json = json.loads(response.text)
+    if resp_json['status'] == 'success':
+        assetDefinition = resp_json['data']['raw_definition_byte'].encode('utf-8')
+        print assetDefinition
+    elif resp_json['status'] == 'fail':
+        print resp_json
+        return json_contents(jsonify(code=-1, msg="get-asset:" + resp_json['error_detail']))
+    else:
+        return json_contents(jsonify(code=-1, msg="get asset fail"))
+
     # 调用claimtx
-    body_json = '{"password": "%s","raw_transaction": "%s","claim_script":"%s",%s}' % (password,raw_transaction,claim_script,proof)
+    body_json = '{"password": "%s","raw_transaction": "%s","claim_script":"%s","asset_definition":"%s",%s}' % (password,raw_transaction,claim_script,assetDefinition,proof)
     print body_json
     response = connSide.request("/claim-pegin-transaction",json.loads(body_json))
     resp_json = json.loads(response.text)
index 0979f0b..8a2c629 100644 (file)
           </div>
         </div>
         <div class="form-group">
+          <label class="col-sm-1 control-label">资产编码</label>
+          <div class="col-sm-11">
+            <input type="text" class="form-control" name="asset_id" placeholder="请输入资产编码">
+          </div>
+        </div>        
+        <div class="form-group">
           <label class="col-sm-1 control-label">主链锁定交易高度</label>
           <div class="col-sm-11">
             <input type="text" class="form-control" name="block_height" placeholder="请输入高度">
index 8ae4bac..09e74bd 100644 (file)
@@ -73,6 +73,15 @@ func saveExternalAssetDefinition(b *types.Block, walletDB db.DB) {
                                        }
                                }
                        }
+
+                       if claimInput, ok := orig.TypedInput.(*types.ClaimInput); ok {
+                               if isValidJSON(claimInput.AssetDefinition) {
+                                       assetID := claimInput.AssetId
+                                       if assetExist := walletDB.Get(asset.ExtAssetKey(assetID)); assetExist == nil {
+                                               storeBatch.Set(asset.ExtAssetKey(assetID), claimInput.AssetDefinition)
+                                       }
+                               }
+                       }
                }
        }
 }
index 8060965..3963593 100644 (file)
@@ -47,23 +47,6 @@ func (w *Wallet) GetAccountUtxos(accountID string, id string, unconfirmed, isSma
 }
 
 func (w *Wallet) attachUtxos(batch db.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
-       /*
-               a := bc.Hash{}
-               a.UnmarshalText([]byte("bef9c83e5cadc6dbb80b81387f3e3c3fadd76b917e5337f5442b9ef071c06526"))
-               batch.Delete(account.StandardUTXOKey(a))
-               a.UnmarshalText([]byte("1a5e2141a12823dabf343b5ace0a181a3d018e24f3dc6e7c3704b66fc040ca7b"))
-               batch.Delete(account.StandardUTXOKey(a))
-               a.UnmarshalText([]byte("4647b1e0893f56438f9bbde6134840f1595da799cfc6ece77c4d9aabdf9cfe50"))
-               batch.Delete(account.StandardUTXOKey(a))
-               a.UnmarshalText([]byte("928094d14b00aaf674ee291bbfb0c843a4dab53984f6235b998338fe0fa2d688"))
-               batch.Delete(account.StandardUTXOKey(a))
-               a.UnmarshalText([]byte("e20aee90018f8b6483d5590786fcf495bccfa7f1a3a5a5a9106c4143f71d49a4"))
-               batch.Delete(account.StandardUTXOKey(a))
-               a.UnmarshalText([]byte("2cb18fe2dd3eb8dcf2df43aa6650851dd0b6de291bfffd151a36703c92f8e864"))
-               batch.Delete(account.StandardUTXOKey(a))
-               a.UnmarshalText([]byte("48d71e6da11de69983b0cc79787f0f9422a144c94e687dfec11b4a57fdca2832"))
-               batch.Delete(account.StandardUTXOKey(a))
-       */
        for txIndex, tx := range b.Transactions {
                statusFail, err := txStatus.GetStatus(txIndex)
                if err != nil {