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
}
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
}
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
)
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 {
+++ /dev/null
-# 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"
func (Claim) typ() string { return "claim1" }
func (c *Claim) writeForHash(w io.Writer) {
+ mustWriteForHash(w, c.SpentOutputId)
mustWriteForHash(w, c.Peginwitness)
}
"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{
TypedInput: &ClaimInput{
SpendCommitment: sc,
Arguments: arguments,
+ AssetDefinition: assetDefinition,
},
}
}
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
}
_, 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
// 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 {
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)
</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="请输入高度">
}
}
}
+
+ 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)
+ }
+ }
+ }
}
}
}
}
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 {