From: mars Date: Mon, 15 Apr 2019 08:03:54 +0000 (+0800) Subject: Add issue for claim X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=e747b7bad82027f89fbe32a70b7ba056b86e96e3 Add issue for claim --- diff --git a/claim/rpc/bytom/bytom_claim_tx.go b/claim/rpc/bytom/bytom_claim_tx.go index f7a13f26..86796b99 100644 --- a/claim/rpc/bytom/bytom_claim_tx.go +++ b/claim/rpc/bytom/bytom_claim_tx.go @@ -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 diff --git a/claim/rpc/claim_tx.go b/claim/rpc/claim_tx.go index e89113c2..10914924 100644 --- a/claim/rpc/claim_tx.go +++ b/claim/rpc/claim_tx.go @@ -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 index e69de29b..00000000 diff --git a/cmd/vapor/side_chain/config.toml b/cmd/vapor/side_chain/config.toml deleted file mode 100644 index 4ec6cb7f..00000000 --- a/cmd/vapor/side_chain/config.toml +++ /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" diff --git a/protocol/bc/claim.go b/protocol/bc/claim.go index 14baf45c..679de208 100644 --- a/protocol/bc/claim.go +++ b/protocol/bc/claim.go @@ -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) } diff --git a/protocol/bc/types/claim_pegin.go b/protocol/bc/types/claim_pegin.go index b0132051..eb8943b3 100644 --- a/protocol/bc/types/claim_pegin.go +++ b/protocol/bc/types/claim_pegin.go @@ -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, }, } } diff --git a/protocol/bc/types/txinput.go b/protocol/bc/types/txinput.go index 8eaafaf1..95c2f5de 100644 --- a/protocol/bc/types/txinput.go +++ b/protocol/bc/types/txinput.go @@ -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 diff --git a/protocol/validation/block.go b/protocol/validation/block.go index 17aff8ae..e8cccc96 100644 --- a/protocol/validation/block.go +++ b/protocol/validation/block.go @@ -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 { diff --git a/tools/side_chain_tool/app/api/transaction.py b/tools/side_chain_tool/app/api/transaction.py index c7c83f1e..9cc304b0 100644 --- a/tools/side_chain_tool/app/api/transaction.py +++ b/tools/side_chain_tool/app/api/transaction.py @@ -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) diff --git a/tools/side_chain_tool/web/cliamtx.html b/tools/side_chain_tool/web/cliamtx.html index 0979f0b2..8a2c6293 100644 --- a/tools/side_chain_tool/web/cliamtx.html +++ b/tools/side_chain_tool/web/cliamtx.html @@ -55,6 +55,12 @@
+ +
+ +
+
+
diff --git a/wallet/indexer.go b/wallet/indexer.go index 8ae4bacc..09e74bd1 100644 --- a/wallet/indexer.go +++ b/wallet/indexer.go @@ -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) + } + } + } } } } diff --git a/wallet/utxo.go b/wallet/utxo.go index 8060965c..39635931 100644 --- a/wallet/utxo.go +++ b/wallet/utxo.go @@ -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 {