Skip to content

Instantly share code, notes, and snippets.

@xxuejie
Last active March 28, 2020 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xxuejie/c9f7fadcccc43aa2a38d30bca23fd3fc to your computer and use it in GitHub Desktop.
Save xxuejie/c9f7fadcccc43aa2a38d30bca23fd3fc to your computer and use it in GitHub Desktop.
$ cat << EOF > market_data.json
{
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"lease_period": "0x64",
"overdue_period": "0x64",
"amount_per_period": "0x91494c600",
"lease_amounts": "0x12309ce54000"
}
EOF
$ curl http://localhost:3000/matches/create -H "Content-Type: application/json" -d @market_data.json
{
"id": "3fb6c534-758e-45a2-af57-1ac775c43f9d",
"data": {
"status": "created",
"info": {
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"lease_period": "0x64",
"overdue_period": "0x64",
"amount_per_period": "0x91494c600"
},
"lease_amounts": "0x12309ce54000"
}
}
$ curl http://localhost:3000/matches/list -H "Content-Type: application/json" -d '' | jq
[
{
"id": "a5de708f-c48d-47cc-bdc7-6abf57d26189",
"data": {
"status": "created",
"info": {
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"lease_period": "0x64",
"overdue_period": "0x64",
"amount_per_period": "0x91494c600"
},
"lease_amounts": "0x12309ce54000"
}
}
]
$ curl http://localhost:3000/matches/3fb6c534-758e-45a2-af57-1ac775c43f9d/match -H "Content-Type: application/json" -d '{"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"}' | jq
{
"id": "3fb6c534-758e-45a2-af57-1ac775c43f9d",
"data": {
"status": "matched",
"info": {
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"lease_period": "0x64",
"overdue_period": "0x64",
"amount_per_period": "0x91494c600",
"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"last_payment_time": "0x592"
},
"messagesToSign": [
{
"index": 0,
"message": "0x5fb82d29cab7c9460bbcacf13dd5ef3cacb5582ad3b901675bb28f09a76ef73a",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"
}
}
],
"nextMessagesToSign": [
{
"index": 2,
"message": "0x55493c0dd56bd00b35a8cb84654ddc52906589dae5f905f2240c36b3cd87786c",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48"
}
}
]
}
}
$ # holder signs the message in messagesToSign and call the API with the signatures
$ curl http://localhost:3000/matches/3fb6c534-758e-45a2-af57-1ac775c43f9d/sign_match -H "Content-Type: application/json" -d '{"signatures": ["0xcad62cb67533bfcbc42657bfb405cf0d7658a27dc0f0ae379163afd9a93d8856767643d4b81bed800d02aa42ec3a4f93b14ea84507c329e3f08af5faca6ac9ad01"]}' | jq
{
"id": "3fb6c534-758e-45a2-af57-1ac775c43f9d",
"data": {
"status": "sign_matched",
"info": {
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"lease_period": "0x64",
"overdue_period": "0x64",
"amount_per_period": "0x91494c600",
"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"last_payment_time": "0x592"
},
"messagesToSign": [
{
"index": 2,
"message": "0x55493c0dd56bd00b35a8cb84654ddc52906589dae5f905f2240c36b3cd87786c",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48"
}
}
]
}
}
$ # developer signs the message in messagesToSign and respond to finalize the lease:
$ curl http://localhost:3000/matches/3fb6c534-758e-45a2-af57-1ac775c43f9d/sign_confirm -H "Content-Type: application/json" -d '{"signatures": ["0x7ec49227f0e4fce8194845a868ab3dcd89e5694153cdd2289b45303045603ad47b520eff8e741c29ce4b1181afa2c8921889741675ec747d0de6390e380942be01"]}'
{"tx_hash":"0xa8ccef0cc7e5c33f30e72e57633a000e02c04317ff3ae9e94fbddd97b905eb89"}
$ curl http://localhost:3000/balances/0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7 -d '' | jq
{
"balance": "0x1bc15030f3507700"
}
$ curl http://localhost:3000/tip_header -d '' | jq
{
"tip_number": "0x7ef"
}
$ export HOLDER1_PK="0xd00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc"
$ export HOLDER1_PUB_KEY_HASH="0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"
$ export HOLDER2_PK="0x63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d"
$ export HOLDER2_PUB_KEY_HASH="0x470dcdc5e44064909650113a274b3b36aecb6dc7"
$ export BUILDER1_PK="0xc132966fa84d33fdbe1aec7ecc8e00b9192941123a7f2fa4b3c3e668110181b7"
$ export BUILDER1_PUB_KEY_HASH="0x276f2fa3565a10c76164a5e92d4a0b699889ef48"
$ curl http://localhost:3000/holders/0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7/cells -d '' | jq
[
{
"lease_info": {
"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"lease_period": "0x64",
"overdue_period": "0x64",
"last_payment_time": "0x1c3",
"amount_per_period": "0x4a817c800"
},
"out_point": {
"tx_hash": "0x24ef00be3fcbc62547e1183ae595a0405ef32fbc238629c1c19d658cafd1df31",
"index": "0x0"
},
"data": "0x746869736973616c6561736563656c6c"
},
{
"lease_info": {
"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"lease_period": "0x64",
"overdue_period": "0x64",
"last_payment_time": "0x1bd",
"amount_per_period": "0x91494c600"
},
"out_point": {
"tx_hash": "0xca1b8ef4c63d9aab952e7826d3ae71c9b651181e8b3ed84fce26cd021dad7673",
"index": "0x0"
},
"data": "0x746869736973616c6561736563656c6c"
}
]
$ curl http://localhost:3000/builders/0x276f2fa3565a10c76164a5e92d4a0b699889ef48/cells -d '' | jq
[
{
"lease_info": {
"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"lease_period": "0x64",
"overdue_period": "0x64",
"last_payment_time": "0x1c3",
"amount_per_period": "0x4a817c800"
},
"out_point": {
"tx_hash": "0x24ef00be3fcbc62547e1183ae595a0405ef32fbc238629c1c19d658cafd1df31",
"index": "0x0"
},
"data": null
},
{
"lease_info": {
"holder_pubkey_hash": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"builder_pubkey_hash": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48",
"coin_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"lease_period": "0x64",
"overdue_period": "0x64",
"last_payment_time": "0x1bd",
"amount_per_period": "0x91494c600"
},
"out_point": {
"tx_hash": "0xca1b8ef4c63d9aab952e7826d3ae71c9b651181e8b3ed84fce26cd021dad7673",
"index": "0x0"
},
"data": null
}
]
$ curl http://localhost:3000/builders/0x276f2fa3565a10c76164a5e92d4a0b699889ef48/cell/0x24ef00be3fcbc62547e1183ae595a0405ef32fbc238629c1c19d658cafd1df31/0x0/change_data -H "Content-Type: application/json" -d '{"data": "changedcelldata"}' | jq
{
"id": "aad2e272-7330-4c80-84c9-382c983b7906",
"messagesToSign": [
{
"index": 0,
"message": "0x450cd0eaa05644d350b414ffe3ac004848c97c31ef9ba5b0b88b9aed3f3c40c6",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48"
}
},
{
"index": 1,
"message": "0x450cd0eaa05644d350b414ffe3ac004848c97c31ef9ba5b0b88b9aed3f3c40c6",
"lock": {
"code_hash": "0x3de0499b41e86df8ef3fb4a5712a9439ad42bf9dfeebcbd959daf7e1fac575bd",
"hash_type": "data",
"args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7276f2fa3565a10c76164a5e92d4a0b699889ef48000000000000000000000000000000000000000000000000000000000000000064000000000000006400000000000000870200000000000000c6941409000000"
}
}
]
}
$ # sign the 2 messages, and prepare the data to send here:
$ cat << EOF > data.json
{
"id": "aad2e272-7330-4c80-84c9-382c983b7906",
"signatures": [
"0x36448a5fc2c19e76c30dd9bdd69d7eb0a2208034fb90e5eb7903c31b5e598f413fb92bc87a1540c2f9eb3496dd7206b95671dbb5413176114afbbdffc1c8507c00",
"0x36448a5fc2c19e76c30dd9bdd69d7eb0a2208034fb90e5eb7903c31b5e598f413fb92bc87a1540c2f9eb3496dd7206b95671dbb5413176114afbbdffc1c8507c00"
]
}
EOF
$ curl http://localhost:3000/send_signed_transaction -H "Content-Type: application/json" -d @data.json
{"tx_hash":"0xaa0f1126d9c915d0ce337bf87b627178b23528d244e352dc1c83edde3303faf5"}
$ curl http://localhost:3000/builders/0x276f2fa3565a10c76164a5e92d4a0b699889ef48/cell/0xca1b8ef4c63d9aab952e7826d3ae71c9b651181e8b3ed84fce26cd021dad7673/0x0/pay -H "Content-Type: application/json" -d '' | jq
{
"id": "a0b36144-e088-4ef1-b283-5286ff078c49",
"messagesToSign": [
{
"index": 0,
"message": "0x283c5153172f9ffe3a541a7ff485ed0bdcf72b3eb9cbb0c3db6437702d2bd42d",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0x276f2fa3565a10c76164a5e92d4a0b699889ef48"
}
},
{
"index": 1,
"message": "0x283c5153172f9ffe3a541a7ff485ed0bdcf72b3eb9cbb0c3db6437702d2bd42d",
"lock": {
"code_hash": "0x3de0499b41e86df8ef3fb4a5712a9439ad42bf9dfeebcbd959daf7e1fac575bd",
"hash_type": "data",
"args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7276f2fa3565a10c76164a5e92d4a0b699889ef48000000000000000000000000000000000000000000000000000000000000000064000000000000006400000000000000870200000000000000c6941409000000"
}
}
]
}
$ # sign the 2 messages, and prepare the data to send here:
$ cat << EOF > data2.json
{
"id": "a0b36144-e088-4ef1-b283-5286ff078c49",
"signatures": [
"0x1668999087aa9ee3c13fac59e46342b71b8d191675e7397ffe0371bd09af772e6008375702200f275373c2f608438e23938271c609bae317600d1a41659de96001",
"0x1668999087aa9ee3c13fac59e46342b71b8d191675e7397ffe0371bd09af772e6008375702200f275373c2f608438e23938271c609bae317600d1a41659de96001"
]
}
EOF
$ curl http://localhost:3000/send_signed_transaction -H "Content-Type: application/json" -d @data2.json
{"tx_hash":"0x2b33147c300dfe49972f18d88a413e18ed1b89009cfad341dcae26658b292cd1"}
$ curl http://localhost:3000/holders/0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7/cell/0xad6d246206418bd8f4d4cd6450ec2ed66d40229cfe148d64f77f19b54ec3ae54/0x1/claim -d '' | jq
{
"id": "a0b36144-e088-4ef1-b283-5286ff078c40",
"messagesToSign": [
{
"index": 0,
"message": "0x71c321b7bce9b4abbf93926225e0376d61205b24270877dff0e4f98de9510355",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"
}
},
{
"index": 1,
"message": "0x71c321b7bce9b4abbf93926225e0376d61205b24270877dff0e4f98de9510355",
"lock": {
"code_hash": "0x3de0499b41e86df8ef3fb4a5712a9439ad42bf9dfeebcbd959daf7e1fac575bd",
"hash_type": "data",
"args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7276f2fa3565a10c76164a5e92d4a0b699889ef48000000000000000000000000000000000000000000000000000000000000000064000000000000006400000000000000c30100000000000000c817a804000000"
}
}
]
}
$ # sign the 2 messages, and prepare the data to send here:
$ cat << EOF > data3.json
{
"id": "a0b36144-e088-4ef1-b283-5286ff078c40",
"signatures": [
"0x3b755e2590322d15d8737bac59302c3fe4a6c02acf84db58d4cc8efaa67904993325c41b354cdfbcc6b5956e3d3995e08aaefb4cad0bc4e295acb36b608532f900",
"0x3b755e2590322d15d8737bac59302c3fe4a6c02acf84db58d4cc8efaa67904993325c41b354cdfbcc6b5956e3d3995e08aaefb4cad0bc4e295acb36b608532f900"
]
}
EOF
$ curl http://localhost:3000/send_signed_transaction -H "Content-Type: application/json" -d @data3.json
{"tx_hash":"0x1c4cf81fbd5bc698b6106a5f5163683acd0a9b51f4d7c9c853cdd12499bd46af"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment