Author

Topic: A Real P2P Trading Example Including commands and output (Read 1594 times)

newbie
Activity: 59
Merit: 0
I am extremely happy to announce that I achieved real P2P Trading Example Using CFOS, you can read the PDF version here too, I colored it so it's easier to follow what is going on:   http://icoinhost.com/console/file/view/9165/a-real-p2p-trade-on-cfos

Before you read, please make sure you know the basic concept of CFOS, it is a multi-coin system, pls refer to the commandline manual in icoinhost.com

Bob is looking to sell his 100 MYCN coins for 0.03 TEND Cash coin owned by Alice
Alice is looking to buy 100 MYCN coins using her 0.03 TEND Cash coin
Assume they do not know each other and have no trust, and they agree to use Btcft.com as a mediator, we use 2 of 3 Multisig to achieve the transaction automatically.
Alice wants to pay Bob 0.03 TEND coins but prevent Bob from cheating him. First each party creates a new address, and then shares them. Then uses the resulting addresses to make a p2sh address (begins with '3' for ABCoin) that requires both parties to sign to release:
Step 1). Bob created a new address for TEND:
c:\Bob>ABC.Service.exe getnewaddress TEND
1BRVRZwJ5FNv8dP16q8Q2nrRDFNqepkpsi
c:\ Bob >ABC.Service.exe validateaddress 1BRVRZwJ5FNv8dP16q8Q2nrRDFNqepkpsi
{
    "isvalid" : true,
    "address" : "1BRVRZwJ5FNv8dP16q8Q2nrRDFNqepkpsi",
    "ismine" : true,
    "isscript" : false,
    "pubkey" : "03fadb2a16dd7183ebc9c1fa16f252440899ce1f0345b1a93feb8fbf48ba15ca1b",
    "iscompressed" : true,
    "account" : "default"
}
Step 2). Alic created a new address for TEND:
C:\Alice>ABC.Service.exe getnewaddress TEND
1Nx8ePgzbRhyrqwmfZyeHZmqPDfExukK7K
Step 3). Btcft created a new address for TEND:
C:\Btcft>ABC.Service.exe getnewaddress TEND
1CaBbDxQra9bZhrjBTjs9nXfP4R3yPcULP
C:\Btcft>ABC.Service.exe validateaddress 1CaBbDxQra9bZhrjBTjs9nXfP4R3yPcULP
{
    "isvalid" : true,
    "address" : "1CaBbDxQra9bZhrjBTjs9nXfP4R3yPcULP",
    "ismine" : true,
    "isscript" : false,
    "pubkey" : "021f7766648b93c50566b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c3016",
    "iscompressed" : true,
    "account" : "default"
}
Step 4). Alice get the pubkey from Bob and Btcft of their TEND and created a 2-of-3 multisig address
C:\Alice>ABC.Service.exe createmultisig 2 "[\"1Nx8ePgzbRhyrqwmfZyeHZmqPDfExukK7K\", \"021f7766648b93c50566b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c3016\", \"03fadb2a16dd7183ebc9c1fa16f252440899ce1f0345b1a93feb8fbf48ba15ca1b\"]"
{
    "address" : "3F8JeXmNRg3dHrvAgejGeppjVkmh6uQcFa",
    "redeemScript" : "5221023d6142e66b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f776 6648b93c50566b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183eb c9c1fa16f252440899ce1f0345b1a93feb8fbf48ba15ca1b53ae"
}

Step 5). Alice pay 0.03 TEND to this address:
C:\Alice>ABC.Service.exe sendassettoaddress TEND 1AGBNTChFMRvTzY7QFGbvFYXTGqCLsVmzU 3F8JeXmNRg3dHrvAgejGeppjVkmh6uQcFa 0.03
cdb727212f0ee2a14bfa074992eca21afaef83edc4b13d793576c493dea3864c

Step 6). Bob verify the transaction and redeem the transaction in above, and sign it, then send to Alice to sign (KwXJsTnEGravvTdctD8g72Nka2GmtPgRMHPKwjqFgZLjgPTScRxh is the privkey of 1BRVRZwJ5FNv8dP16q8Q2nrRDFNqepkpsi):
C:\Bob>ABC.Service.exe getrawtransaction cdb727212f0ee2a14bfa074992eca21afaef83edc4b13d793576c493dea3864c  1
{
    "hex" : "01000000019e5802f71939b054ba83fecba6016ebb4178a48c9348eaedd8bb42df980737f800000 0006b4830450221009d1208cd8b2ac15190c7bd03b652d0b6ca273a718e068c127391d94645e89c 4502205c423aaa0768ed782c315d2ddb7f6cfc1967998cee582bd3a101b78747888f5e012102097 5993b1b7be0ba210f8aa1044a5e44f90ec2dedbeabe87df28b9281fe70f90ffffffff0230757102 000000001976a9146547c3c5485763f09fe439737fbe926c72c4047388acc0c62d000000000017a 9149361fea21cc7d6f1c7ee6d5115c1cd1402b7de0c8700000000",
    "txid" : "cdb727212f0ee2a14bfa074992eca21afaef83edc4b13d793576c493dea3864c",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "f8370798df42bbd8edea48938ca47841bb6e01a6cbfe83ba54b03919f702589e",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "30450221009d1208cd8b2ac15190c7bd03b652d0b6ca273a718e068c127391d94645e89c4502205 c423aaa0768ed782c315d2ddb7f6cfc1967998cee582bd3a101b78747888f5e01 020975993b1b7be0ba210f8aa1044a5e44f90ec2dedbeabe87df28b9281fe70f90",
                "hex" : "4830450221009d1208cd8b2ac15190c7bd03b652d0b6ca273a718e068c127391d94645e89c45022 05c423aaa0768ed782c315d2ddb7f6cfc1967998cee582bd3a101b78747888f5e0121020975993b 1b7be0ba210f8aa1044a5e44f90ec2dedbeabe87df28b9281fe70f90"
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 0.40990000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 6547c3c5485763f09fe439737fbe926c72c40473 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a9146547c3c5485763f09fe439737fbe926c72c4047388ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1AEXDgBvmkpYWwQ3Hfg1G8iLPqNYJeKgZM"
                ]
            }
        },
        {
            "value" : 0.03000000,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_HASH160 9361fea21cc7d6f1c7ee6d5115c1cd1402b7de0c OP_EQUAL",
                "hex" : "a9149361fea21cc7d6f1c7ee6d5115c1cd1402b7de0c87",
                "reqSigs" : 1,
                "type" : "scripthash",
                "addresses" : [
                    "3F8JeXmNRg3dHrvAgejGeppjVkmh6uQcFa"
                ]
            }
        }
    ],
    "blockhash" : "000000140bcb53765aaf7576e05f9caca2de9f463333d263a559506255c9a4be",
    "confirmations" : 2,
    "time" : 1406498806,
    "blocktime" : 1406498806
}

Bob redeem and sign it and send to Alice to sign:
c:\Bob>ABC.Service.exe createrawtransaction "[{\"txid\":\"cdb727212f0ee2a14bfa074992eca21afaef83edc4b13d793576c493dea3864c\",\"vout\":1}]" "{\"1BRVRZwJ5FNv8dP16q8Q2nrRDFNqepkpsi\":0.0299}"
01000000014c86a3de93c47635793db1c4ed83effa1aa2ec924907fa4ba1e20e2f2127b7cd01000 00000ffffffff01b09f2d00000000001976a9147252f7bd648396edbfab11360fe56c8902c193ec 88ac00000000

c:\Bob>c:\dist>ABC.Service.exe signrawtransaction "01000000014c86a3de93c47635793db1c4ed83effa1aa2ec924907fa4ba1e20e2f2127b7cd01000 00000ffffffff01b09f2d00000000001976a9147252f7bd648396edbfab11360fe56c8902c193ec 88ac00000000" "[{\"txid\":\"cdb727212f0ee2a14bfa074992eca21afaef83edc4b13d793576c493dea3864c\",\"vout\":1,\"scriptPubKey\":\"a9149361fea21cc7d6f1c7ee6d5115c1cd1402b7de0c87\",\"redeemScript\":\"5221023d6142e66b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f776 6648b93c50566b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183eb c9c1fa16f252440899ce1f0345b1a93feb8fbf48ba15ca1b53ae\"}]"  "[\"KwXJsTnEGravvTdctD8g72Nka2GmtPgRMHPKwjqFgZLjgPTScRxh\"]"
{
    "hex" : "01000000014c86a3de93c47635793db1c4ed83effa1aa2ec924907fa4ba1e20e2f2127b7cd01000 000b40047304402203022c7ad4a5367316ee761f9805b486ce13a7a7a9b1fc2aa23701b848052a7 7302201b40b3c004f374ff51cf05fcc15634c1c37329a2c5185e1c98bc03142c4dc563014c69522 1023d6142e66b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f776664 8b93c50566b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183ebc9c 1fa16f252440899ce1f0345b1a93feb8fbf48ba15ca1b53aeffffffff01b09f2d00000000001976 a9147252f7bd648396edbfab11360fe56c8902c193ec88ac00000000",
    "complete" : false
}

Step 7). Bob sends 100 MYCN coins to Alice, Output is ignored because it is too simple:
 ABC.Service.exe sendassettoaddress MYCN fromaddress toaddress 100
Step 8 ). Alice signs the transaction and broadcast (L31WfZ3Ldz9aXq62nSEBmyWMyL5cncWZ35XUGHVcRyrkx4UP6krc is the privkey of 1Nx8ePgzbRhyrqwmfZyeHZmqPDfExukK7K),   If Alice does not sign for Bob, then Btcft will sign for him to finish the Trade.
C:\Alice>ABC.Service.exe signrawtransaction "01000000014c86a3de93c47635793db1c4ed83effa1aa2ec924907fa4ba1e20e2f2127b7cd01000 000b40047304402203022c7ad4a5367316ee761f9805b486ce13a7a7a9b1fc2aa23701b848052a7 7302201b40b3c004f374ff51cf05fcc15634c1c37329a2c5185e1c98bc03142c4dc563014c69522 1023d6142e66b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f776664 8b93c50566b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183ebc9c 1fa16f252440899ce1f0345b1a93feb8fbf48ba15ca1b53aeffffffff01b09f2d00000000001976 a9147252f7bd648396edbfab11360fe56c8902c193ec88ac00000000" "[{\"txid\":\"cdb727212f0ee2a14bfa074992eca21afaef83edc4b13d793576c493dea3864c\",\"vout\":1,\"scriptPubKey\":\"a9149361fea21cc7d6f1c7ee6d5115c1cd1402b7de0c87\",\"redeemScript\":\"5221023d6142e6
6b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f7766648b93c50566b 4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183ebc9c1fa16f25244 0899ce1f0345b1a93feb8fbf48ba15ca1b53ae\"}]"  "[\"L31WfZ3Ldz9aXq62nSEBmyWMyL5cncWZ35XUGHVcRyrkx4UP6krc\"]"
{
    "hex" : "01000000014c86a3de93c47635793db1c4ed83effa1aa2ec924907fa4ba1e20e2f2127b7cd01000 000fdfd00004830450221009f670ea1bfc8117fa4c982e397c7415a1a59920934bc48f364b0f9a0 5053f881022041f92642c530ed6555c148e69aafd8adb925c95c67b4464b36594ee116ae9d1a014 7304402203022c7ad4a5367316ee761f9805b486ce13a7a7a9b1fc2aa23701b848052a77302201b 40b3c004f374ff51cf05fcc15634c1c37329a2c5185e1c98bc03142c4dc563014c695221023d614 2e66b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f7766648b93c505 66b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183ebc9c1fa16f25 2440899ce1f0345b1a93feb8fbf48ba15ca1b53aeffffffff01b09f2d00000000001976a9147252 f7bd648396edbfab11360fe56c8902c193ec88ac00000000",
    "complete" : true
}

C:\Alice>ABC.Service.exe sendrawtransaction 01000000014c86a3de93c47635793db1c4ed83effa1aa2ec924907fa4ba1e20e2f2127b7cd01000 000fdfd00004830450221009f670ea1bfc8117fa4c982e397c7415a1a59920934bc48f364b0f9a0 5053f881022041f92642c530ed6555c148e69aafd8adb925c95c67b4464b36594ee116ae9d1a014 7304402203022c7ad4a5367316ee761f9805b486ce13a7a7a9b1fc2aa23701b848052a77302201b 40b3c004f374ff51cf05fcc15634c1c37329a2c5185e1c98bc03142c4dc563014c695221023d614 2e66b60ba2ead531812bd48257573ffa983db668715a2de1598a5100dae21021f7766648b93c505 66b4eacba7adea2d2cd51d68da40ac4fd2e82fb8041c30162103fadb2a16dd7183ebc9c1fa16f25 2440899ce1f0345b1a93feb8fbf48ba15ca1b53aeffffffff01b09f2d00000000001976a9147252 f7bd648396edbfab11360fe56c8902c193ec88ac00000000
6a9bffebab1c1c8081203dc5785dabe18c3406197007f39fac728ed0f4d24901


----------------------------I copied the output of our blockchain explorer here----------------------------------6a9bffebab1c1c8081203dc5785dabe18c3406197007f39fac728ed0f4d24901--------------------------------------------------------  on Block chain explorer--------------------------
 
Short Link: http://btccds.com:2750/b/9jbJXPnf1
Hash: 000000f94fbea4c4600fbe1a9b7af11e4ae8c20242d7a7c497240caadcbc6567
Previous Block: 0000004c26cf9c88cc41df106fcc11ae79432eca9e0a50a7ff3d59a9675769f1
Next Block: 000000483e2f32f4570147b92e974bb1389f1ee246606f673ae1583bfc687d3d
Height: 1958
Version: 2
Transaction Merkle Root: 40d4ab236b33fda99ddbb3db31944c5bf28e13dd60563b73db529815ba5f5e6a
Time: 1406507451 (2014-07-28 00:30:51)
Difficulty: 0.003 (Bits: 1e00ffff)
Cumulative Difficulty: 7.652
Nonce: 3371108608
Transactions: 2
Value out: 1.03
Transaction Fees: 0.0001
Average Coin Age: 2.00852 days
Coin-days Destroyed: 0.00300173
Cumulative Coin-days Destroyed: 94.609%
Transactions
Symbol   assetType   Unit   Transaction   Fee   Size (kB)   From (amount)   To (amount)
ABC   coin   1   bfcf0217a2...
0   0.107   Generation: 1 + 0.0001 total fees   154JCMXHfRuGgfz2RPxko8sT8qihckcQpC: 1.0001
ABC   coin   1   6a9bffebab...
0.0001   0.34   UNKNOWN: 0.03   1BRVRZwJ5FNv8dP16q8Q2nrRDFNqepkpsi: 0.0299

API (machine-readable pages)




------------------------------------------------------------------------------------------------------------------------------------------------------------------

Notice:     If Alice does not sign for Bob, then Btcft will sign for him to finish the Trade.



Jump to: