Open NadigerAmit opened 4 months ago
This is a duplicate of #3 . I don't know Why I created this. I will use this ticket to axum web server implementation.
Below is the sequence of operations I did to test for the buy kitty operation :
Note: we need two users here. Hence 2 sets of key pairs are required.
In the web service, I am inserting the default key i.e public: d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67
<-- let's call this as a buyer key.
Note that when we use the DApp with an external wallet such as Talisman wallet, we can't use the above default user/key since the web-service will not have a keystore.
Now let's start testing: We already have the Buyer key as explained above.
1. Generate Key for Seller: --> This operation is not required in the DApp since keys will be handled in the external wallet such as Talisman .
**Curl Command:** curl -X POST -H "Content-Type: application/json" -d '{"password": null}' http://localhost:3000/debug-generate-key
**O/P :** {"message":"Keys generated successfully","public_key":"**fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223**","phrase":"west coconut juice carry mass only weather sustain kick flower lounge regret"}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X POST -H "Content-Type: application/json" -d '{"password": null}' http://localhost:3000/debug-generate-key
Mint coins from the buyer: <- This is required since we need some money to buy kitty.
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X POST -H "Content-Type: application/json" -d '{"amount": 200,"owner_public_key":"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"}' http://localhost:3000/post-mint-coin
{"message":"Coins minted successfully"}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X POST -H "Content-Type: application/json" -d '{"amount": 300,"owner_public_key":"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"}' http://localhost:3000/mint-coins
{"message":"Coins minted successfully"}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-coins
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-coins
{"message":"Success: Found Coins","coins":[["136241943cc761b07a15a845fef70d092623fd052c7acf17a1a5b3eef3a4842b00000000","0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67",300],["4d732d8b0d0995151617c5c3beb600dc07a9e1be9fc8e95d9c792be42d65911000000000","0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67",200]]}
Test result:
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X POST -H "Content-Type: application/json" -d '{"name": "amit","owner_public_key":"fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}' http://localhost:3000/post-create-kitty
{"message":"Kitty created successfully","kitty":{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]}}
4.1: Created one more kitty just for demo purposes < Not used anywhere. So you skip this step.
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X POST -H "Content-Type: application/json" -d '{"name": "amit","owner_public_key":"fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}' http://localhost:3000/post-create-kitty
{"message":"Kitty created successfully","kitty":{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]}}
curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-kitty-list
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-kitty-list
{"message":"Success: Found Kitties","kitty_list":[{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]},{"parent":{"Dad":"RearinToGo"},"free_breedings":2,"dna":"0xa2a2c882bdb1742588a129dcc9762d5eef1e74a5515de9d30314cc8c95797719","num_breedings":0,"name":[115,114,97,109]}]}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-kitty-list GET -H "Content-Type: application/json" -H "owner_public_key: fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223" http://localhost:3000/get-owned-kitty-list
{"message":"Success: Found Kitties","kitty_list":[{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]},{"parent":{"Dad":"RearinToGo"},"free_breedings":2,"dna":"0xa2a2c882bdb1742588a129dcc9762d5eef1e74a5515de9d30314cc8c95797719","num_breedings":0,"name":[115,114,97,109]}]}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
6. List kitty for sale: It involves 2 steps (get transaction and send signed transaction )
6.1 : Get the raw transaction from web service:
Curl command: curl -X GET -H "Content-Type: application/json" -H "kitty-dna: kittyDNA" -H "kitty-price: 200" -H "owner_public_key: seller_pub_key" http://localhost:3000/get-txn-and-inpututxolist-for-listkitty-forsale
Test result:
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" -H "kitty-dna: bc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6" -H "kitty-price: 200" -H "owner_public_key: fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223" http://localhost:3000/get-txn-and-inpututxolist-for-listkitty-forsale
{"message":"List kitty for Sale txn created successfully","transaction":{"inputs":[{"output_ref":{"tx_hash":"0x8846e532084405d448e4fc9865fc1a7c9513f6811c72f460b0a1f52415254f10","index":0},"redeemer":[]}],"peeks":[],"outputs":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[116,100,107,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}}],"checker":{"TradableKitty":"ListKittiesForSale"}},"input_utxo_list":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116],"type_id":[75,105,116,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}}]}
6.2 : Sign the above transaction and attach the redeemer where the redeemer is blank in the above transaction:
6.3 send the signed transaction to web service for interacting with blockchain:
Curl command :
curl -X PUT \
-H "Content-Type: application/json" \
-d '{
"signed_transaction": transaction' \
http://localhost:3000/put-listkitty-for-sale
Test result:
curl -X PUT \
-H "Content-Type: application/json" \
-d '{
"signed_transaction": {"inputs":[{"output_ref":{"tx_hash":"0x8846e532084405d448e4fc9865fc1a7c9513f6811c72f460b0a1f52415254f10","index":0},"redeemer":[138, 222, 17, 144, 42, 167, 239, 94, 232, 55, 114, 121, 135, 173, 17, 136, 94, 210, 78, 80, 176, 33, 248, 10, 159, 195, 97, 18, 217, 36, 98, 83, 250, 32, 85, 25, 213, 84, 73, 123, 153, 197, 125, 190, 237, 198, 125, 128, 99, 25, 61, 174, 10, 206, 232, 99, 198, 100, 111, 32, 139, 147, 39, 130]}],"peeks":[],"outputs":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[116,100,107,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}}],"checker":{"TradableKitty":"ListKittiesForSale"}},"input_utxo_list":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116],"type_id":[75,105,116,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}}]}' \
http://localhost:3000/put-listkitty-for-sale
O/P:
{"message":"Kitty listed for sale successfully","td_kitty":{"kitty_basic_data":{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]},"price":200}}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-tradable-kitty-list
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-tradable-kitty-list
{"message":"Success: Found TradableKitties","td_kitty_list":[{"kitty_basic_data":{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]},"price":200}]}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
9.1 : get the raw transaction for buying kitty
Curl command: ``
curl -X GET -H "Content-Type: application/json" -H "kitty-dna: kittyDna" -H "input-coins: coin_referance" -H "output_amount: 200" -H "buyer_public_key: public_key_of_Buyer" -H "seller_public_key: publick_key_of_seller" http://localhost:3000/get-txn-and-input utxolist-for-buy-kitty`
Test results:
curl -X GET -H "Content-Type: application/json" -H "kitty-dna: bc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6" -H "input-coins: 4d732d8b0d0995151617c5c3beb600dc07a9e1be9fc8e95d9c792be42d65911000000000" -H "output_amount: 200" -H "buyer_public_key: d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67" -H "seller_public_key: fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223" http://localhost:3000/get-txn-and-input
utxolist-for-buy-kitty
O/P of the above command gives the transaction:
{"message":"Kitty name update txn created successfully","transaction":{"inputs":[{"output_ref":{"tx_hash":"0x9bffe2abf274e0008f3f34af60cd083e909f884f2064e10f25ca46166306ae81","index":0},"redeemer":[]},{"output_ref":{"tx_hash":"0x4d732d8b0d0995151617c5c3beb600dc07a9e1be9fc8e95d9c792be42d659110","index":0},"redeemer":[]}],"peeks":[],"outputs":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[116,100,107,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"}}},{"payload":{"data":[200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[99,111,105,0]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}}],"checker":{"TradableKitty":"Buy"}},"input_utxo_list":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[116,100,107,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}},{"payload":{"data":[200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[99,111,105,0]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"}}}]}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
9.2: Sign the transaction i.e add the redeemer to the above transaction for all inputs
9.3: Send the signed transaction to the web service: Curl command:
`curl -X PATCH -H "Content-Type: application/json" -d '{ "signed_transaction":signed_transaction' http://localhost:3000/patch-buy-kitty
curl -X PATCH -H "Content-Type: application/json" -d '{ "signed_transaction": {"inputs":[{"output_ref":{"tx_hash":"0x9bffe2abf274e0008f3f34af60cd083e909f884f2064e10f25ca46166306ae81","index":0},"redeemer":[134, 152, 55, 235, 162, 163, 255, 144, 247, 94, 237, 234, 127, 220, 149, 66, 226, 223, 43, 116, 16, 156, 165, 251, 221, 234, 13, 136, 132, 189, 187, 27, 206, 197, 48, 23, 188, 43, 41, 94, 103, 242, 174, 100, 249, 158, 206, 55, 88, 199, 103, 246, 227, 126, 138, 252, 205, 7, 132, 3, 112, 239, 52, 129]},{"output_ref":{"tx_hash":"0x4d732d8b0d0995151617c5c3beb600dc07a9e1be9fc8e95d9c792be42d659110","index":0},"redeemer":[166, 2, 32, 88, 200, 30, 54, 252, 155, 169, 122, 237, 29, 44, 33, 22, 102, 77, 71, 128, 35, 214, 84, 147, 193, 59, 45, 110, 69, 52, 25, 75, 5, 248, 227, 232, 110, 165, 177, 178, 218, 240, 235, 61, 25, 248, 242, 132, 106, 115, 62, 88, 57, 238, 39, 150, 202, 64, 237, 111, 147, 210, 215, 131]}],"peeks":[],"outputs":[{"payload":{"data":[0,0,2,0,0,0,0,0,0,0,188,20,115,3,247,208,163,97,172,34,165,11,242,202,46,197,19,217,38,163,39,237,103,136,39,201,13,101,18,254,173,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,109,105,116,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[116,100,107,116]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"}}},{"payload":{"data":[200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"type_id":[99,111,105,0]},"verifier":{"Sr25519Signature":{"owner_pubkey":"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223"}}}],"checker":{"TradableKitty":"Buy"}}}' http://localhost:3000/patch-buy-kitty
The buying of the kitty is completed. i.e Buy transaction is a success
Kitty is transferred to Buyer i.e --> d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67
Coin of value 200 is transferred to seller i.e fab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223 Coin transfer : ["5dc6c2f7684bcf87ea2f51502ff03621b510dbaaa9074bf830a65c9e3542411601000000","0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223",200]
See below commands for confirmation:
1. Money transfer from buyer to seller:
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" http://localhost:3000/get-all-coins
{"message":"Success: Found Coins","coins":[["136241943cc761b07a15a845fef70d092623fd052c7acf17a1a5b3eef3a4842b00000000","0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67",300],["5dc6c2f7684bcf87ea2f51502ff03621b510dbaaa9074bf830a65c9e3542411601000000",**"0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223",200**]]}
Buyer gets the tradable kitty:
amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$ curl -X GET -H "Content-Type: application/json" -H "owner_public_key: **d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67**" http://localhost:3000/get-owned-tradable-kitty-list
{"message":"Success: Found TradableKitties","td_kitty_list":[{"kitty_basic_data":{"parent":{"Mom":"RearinToGo"},"free_breedings":2,"dna":"0xbc147303f7d0a361ac22a50bf2ca2ec513d926a327ed678827c90d6512feadd6","num_breedings":0,"name":[97,109,105,116]},"price":200}]}amit@DESKTOP-TF687VE:~/OmBlockchain/OmTest$
Below are blockchain logs:
2024-03-31 22:00:33.003 INFO tokio-runtime-worker tuxedo-core: validating tuxedo transaction
2024-03-31 22:00:33.003 INFO tokio-runtime-worker tuxedo-core: input_set.len() 0 and transaction.inputs.len() 0
2024-03-31 22:00:33.004 INFO tokio-runtime-worker tuxedo_template_runtime: runtime-> apply_extrinsic Transaction { inputs: [Input { output_ref: OutputRef { tx_hash: 0x9bffe2abf274e0008f3f34af60cd083e909f884f2064e10f25ca46166306ae81, index: 0 }, redeemer: [134, 152, 55, 235, 162, 163, 255, 144, 247, 94, 237, 234, 127, 220, 149, 66, 226, 223, 43, 116, 16, 156, 165, 251, 221, 234, 13, 136, 132, 189, 187, 27, 206, 197, 48, 23, 188, 43, 41, 94, 103, 242, 174, 100, 249, 158, 206, 55, 88, 199, 103, 246, 227, 126, 138, 252, 205, 7, 132, 3, 112, 239, 52, 129] }, Input { output_ref: OutputRef { tx_hash: 0x4d732d8b0d0995151617c5c3beb600dc07a9e1be9fc8e95d9c792be42d659110, index: 0 }, redeemer: [166, 2, 32, 88, 200, 30, 54, 252, 155, 169, 122, 237, 29, 44, 33, 22, 102, 77, 71, 128, 35, 214, 84, 147, 193, 59, 45, 110, 69, 52, 25, 75, 5, 248, 227, 232, 110, 165, 177, 178, 218, 240, 235, 61, 25, 248, 242, 132, 106, 115, 62, 88, 57, 238, 39, 150, 202, 64, 237, 111, 147, 210, 215, 131] }], peeks: [], outputs: [Output { payload: DynamicallyTypedData { data: [0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 188, 20, 115, 3, 247, 208, 163, 97, 172, 34, 165, 11, 242, 202, 46, 197, 19, 217, 38, 163, 39, 237, 103, 136, 39, 201, 13, 101, 18, 254, 173, 214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 109, 105, 116, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], type_id: [116, 100, 107, 116] }, verifier: Sr25519Signature(Sr25519Signature { owner_pubkey: 0xd2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67 }) }, Output { payload: DynamicallyTypedData { data: [200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], type_id: [99, 111, 105, 0] }, verifier: Sr25519Signature(Sr25519Signature { owner_pubkey: 0xfab33c8c12f8df78fa515faa2fcc4bbf7829804a4d187984e13253660a9c1223 }) }], checker: TradableKitty(Buy) }
2024-03-31 22:00:33.004 INFO tokio-runtime-worker tuxedo-core: validating tuxedo transaction
2024-03-31 22:00:33.004 INFO tokio-runtime-worker tuxedo-core: input_set.len() 2 and transaction.inputs.len() 2
2024-03-31 22:00:33.005 INFO tokio-runtime-worker money: Money:Spend called
2024-03-31 22:00:33.005 INFO tokio-runtime-worker money: Money:Spend Total burned for this transaction = 0
2024-03-31 22:00:33.006 INFO tokio-runtime-worker tuxedo_template_runtime: runtime-> finalize_block
This Task is done as per above test results and all the details.
Step1: FE will pass coins and Kitty for buying the kitty. BE will provide API for buy kitty.
Step2: BE will provide the API for getting the transaction for buy kittu which includes below :
FE will get transaction details and sign with the talisman key .
There is Swagger, Need to modify the swagger as to what the rest API will return.