UTXO 交易入门
注意:UTXO每一笔的input都是上一笔的output。理解这句话,就能更容易明白input、output的调用规则了
submitutxotransfertx
用来进行utxo交易
Parameters
sender
(string, required) 发起交易的用户地址
coin_symbol
(string, required) 交易货币类型
vins
(string(json), required) utxo 的输入
vouts
(string(json), required) utxo 的输出
symbol:fee:unit
(symbol:amount:unit, optional) 付给矿工的费用
memo
(string,optinal) 备注
Result
txid
(string) utxo交易生成的哈希
根据vins和vouts的值自动判断交易的状态
状态 | vins | vouts |
---|---|---|
充币 | 空 | 有值 |
花币 | 有值 | 有值 |
提币 | 有值 | 空 |
vins详解
1、prev_utxo_txid: 上个utxo的交易哈希
2、prev_utxo_vout_index: 上个utxo中输出的第几个交易,such as ouput的第几个
3、conds:utxo解锁条件
{
cond_type:11 解地址锁
cond_type:12 解多签锁
cond_type:13 解密码锁
{
password:
}
cond_type:14 解超时锁 达到114类型的UTXO指定高度
cond_type:15 解回收锁 达到115类型的UTXO指定高度
}
以解密码锁为例,vins为:
"[{\"prev_utxo_txid\":\"9d36b478cce47ae3429e6b58ec97e8c54e0764deaff26b2adcd9d37bbc2cb80b\",\"prev_utxo_vout_index\":0,\"conds\":[{\"cond_type\": 13, \"password\": \"123456\"}]"
vouts详解
1、`coin_amount`: 转出的货币数量
2、`conds`: utxo上锁,为空时是无锁状态,根据type有不同的参数
{
cond_type:111 单个锁,地址锁
{
uid:
}
cond_type:112 多签锁
{
multisign_address:
}
cond_type:113 密码锁
{
password_proof_required: 指定唯一性,flase:任何人猜对密码都可以用; true:用submitpasswordprooftx进行认证后,才能用密码进行获取
password:密码长度无限制
}
cond_type:114 超时锁
{
height:块的高度
}
cond_type:115 回收锁
{
height:块的高度;
}
}
以单个锁为例 vouts为:
[{"coin_amount":10000,"conds":[{"cond_type":111,"uid":"0-1"}]
Examples
> ./coind submitutxotransfertx "wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4" "WICC" "[]" "[]" "WICC:10000:sawi" "xx"
// As json rpc call
> curl --user myusername -d '{"jsonrpc": "1.0", "id":"curltest", "method": "submitutxotransfertx", "params": ["wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4", "WICC", "[]", "[]", "WICC:10000:sawi", "xx"] }' -H 'Content-Type: application/json;' http://127.0.0.1:8332/
充币
用户从自己的余额转账给utxo
vins为空,vout有值
无锁
example
// Request
coind submitutxotransfertx "wQ3FinggSoJU7x27J2cdfao9rXdZxCNqoQ" "WICC" "[]" "[{\"coin_amount\":10000,\"conds\":[]}]" "WICC:100000:sawi" "xx"
// Respond
{
"txid" : "cdb2250416487409acd21b4d98f322de9aab5cd7265432c13536c33f4a909eb4"
}
地址锁
example
// Request
root@0e7612ac5bc5:/opt/wicc# coind submitutxotransfertx 0-1 "WICC" "[]" '[{"coin_amount":10000,"conds":[{"cond_type":111,"uid":"0-1"}]}]' "WICC:100000:sawi" "test"
// Respond
{
"txid" : "be685d611ac914b41138ffaa68c87ac3b177c4fb82a7c03bab013fe34452b0f4"
}
密码锁
example
// Request
root@0dc1d946424b:/opt/wicc# coind submitutxotransfertx "wQ3FinggSoJU7x27J2cdfao9rXdZxCNqoQ" "WICC" "[]" "[{\"coin_amount\":100,\"conds\":[{\"cond_type\":113,\"password_proof_required\":true,\"password\":\"123456\"}]}]" "WICC:100000:sawi" "password test"
// Respond
{
"txid" : "6d8c07ae4ea1868e2cb7d458b636acc0204c9a7637036fd7b02e62625b73a01c"
}
花币
vins有值,vout有值
无锁转无锁
example
// Request
coind submitutxotransfertx "wQ3FinggSoJU7x27J2cdfao9rXdZxCNqoQ" "WICC" "[{\"prev_utxo_txid\":\"be685d611ac914b41138ffaa68c87ac3b177c4fb82a7c03bab013fe34452b0f4\",\"prev_utxo_vout_index\":0,\"conds\":[]}]" "[{\"coin_amount\":100000,\"conds\":[]}]" "WICC:1000000:sawi" "spend utxo"
// Response
{
"txid" : "307d44227137eb47006479a8b02c86dd63e995fb024cbcf6aa9c342f36ea4f5c"
}
roo
无锁生成单个锁
example
// Request
root@0dc1d946424b:/opt/wicc# coind submitutxotransfertx "wQ3FinggSoJU7x27J2cdfao9rXdZxCNqoQ" "WICC" "[{\"prev_utxo_txid\":\"307d44227137eb47006479a8b02c86dd63e995fb024cbcf6aa9c342f36ea4f5c\",\"prev_utxo_vout_index\":0,\"conds\":[]}]" "[{\"coin_amount\":100000,\"conds\":[{\"cond_type\":111,\"uid\":\"0-1\"}]}]}]" "WICC:1000000:sawi" "spend utxo"
// Respond
{
"txid" : "9d36b478cce47ae3429e6b58ec97e8c54e0764deaff26b2adcd9d37bbc2cb80b"
}
coind submitutxotransfertx "wQ3FinggSoJU7x27J2cdfao9rXdZxCNqoQ" "WICC" "[]" "[{\"coin_amount\":100,"\coinds\":[\"cond_type\":113,\"password_proof_required\":False,\"password\":123456]]" "WICC:100000:sawi" "password in"
提币
vins无值,vout有值
解密码锁
example
coind submitutxotransfertx "wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4" "WICC" "[{\"prev_utxo_txid\":\"6d8c07ae4ea1868e2cb7d458b636acc0204c9a7637036fd7b02e62625b73a01c\",\"prev_utxo_vout_index\":0,\"conds\":[{\"cond_type\": 13, \"password\":\"123456\"}]}]" "[]" "WICC:1000000:sawi" "parse password"