Elements侧链RPC API文档

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

rawblindrawtransaction - 原始盲化裸交易

rawblindrawtransaction调用使用一个原始的盲化接口来将裸交易的 一个或多个输出盲化为私密交易输出,并返回修改后的裸交易。

用于盲化交易输出的密钥通过给出createrawtransaction私密地址来定义。 由于不需要访问钱包,因此不会尝试添加新的输出。

调用参数

  • Transaction:交易序列化字符串
  • InputBlinders:输入盲化器数组,每个成员为输入的盲化因子,可以从listunspent获得
  • InputAmounts:输入数量数组
  • AssetIdentifiers:资产标识符数组
  • AssetBlinders:资产盲化器数组
  • parameter6: 暂未用
  • ignoreblindfail:是否忽略盲化失败

返回结果

rawblindrawtransaction调用返回盲化处理过的未签名的裸交易字符串。

示例代码

请求bash脚本:

## We'll be using bitcoins in this example
bitcoin_asset_id=09f663de96be771f50cab5ded00256ffe63773e2eaa9a604092951cc3d7c6621

## Create a new address
blinded_addr=$( elements-cli getnewaddress )

## Get the unblinded address
unblinded_addr=$( elements-cli validateaddress $blinded_addr | jq -r .unconfidential )

## Let's create two new inputs by spending some money to the address
txid1=$( elements-cli sendtoaddress $blinded_addr 1 )
txid2=$( elements-cli sendtoaddress $blinded_addr 3 )

## Let's collect the information about the inputs that we'll need later
vout1=$( elements-cli listunspent 0 | jq ".[]|select(.txid == \"$txid1\" and .address == \"$unblinded_addr\") | .vout" )
blinder1=$( elements-cli listunspent 0 | jq -r ".[]|select(.txid == \"$txid1\" and .address == \"$unblinded_addr\") | .blinder" )
assetblinder1=$( elements-cli listunspent 0 | jq -r ".[]|select(.txid == \"$txid1\" and .address == \"$unblinded_addr\") | .assetblinder" )
vout2=$( elements-cli listunspent 0 | jq ".[]|select(.txid == \"$txid2\" and .address == \"$unblinded_addr\") | .vout" )
blinder2=$( elements-cli listunspent 0 | jq -r ".[]|select(.txid == \"$txid2\" and .address == \"$unblinded_addr\") | .blinder" )
assetblinder2=$( elements-cli listunspent 0 | jq -r ".[]|select(.txid == \"$txid2\" and .address == \"$unblinded_addr\") | .assetblinder" )

## Create an unblinded raw transaction
raw_tx=$( 
  elements-cli createrawtransaction '''[
    { "txid": "'$txid1'", "vout": '$vout1', "amount": 1 },
    { "txid": "'$txid2'", "vout": '$vout2', "amount": 3 }
  ]''' '{ "'$blinded_addr'": 3.9, "fee": 0.1 }' 
)

## Blind the transaction
blinded_tx=$(
  elements-cli rawblindrawtransaction $raw_tx \
    "[\"$blinder1\", \"$blinder2\"]" \
    "[1, 3]" \
    "[\"$bitcoin_asset_id\", \"$bitcoin_asset_id\"]" \
    "[\"$assetblinder1\", \"$assetblinder2\"]"
)

## Ensure we can sign it
signed_tx=$( elements-cli signrawtransaction $blinded_tx | jq -r .hex )

## Final validity check: ensure we can broadcast it
elements-cli sendrawtransaction $signed_tx

响应结果:

25999796202a90d44a97194c144424a915a9460fefe91227292627c3aabc5522