Cannot seem to execute atomic transactions between two addresses on same server. Any Ideas?

+1 vote
asked Aug 18, 2016 by Barry

1 Answer

0 votes

There's no reason why this can't be done - you'll have to post your steps. But perhaps the issue is you're calling preparelockunspent instead of preparelockunspentfrom - the latter gives you control over the address whose funds are used.

answered Aug 18, 2016 by MultiChain
We are going to swap 1.5 units of EUR (asset1) from address           "17WvENPL3G57Jo8a1rCzG2VHPsGdmo92jecqQn"          for
                                       1.5 units of USDBCW (asset2) from  address "12GJL31g4NV9yc4JZUwzzNYYSwSZwW41W7W9SR"  


create a locked transaction output containing 1.5 units of BCWEUR (asset2):

preparelockunspentfrom  "12GJL31g4NV9yc4JZUwzzNYYSwSZwW41W7W9SR"  '{"USDBCW":1.5}'

    "txid" : "a4230175cfbe40a73ed21966406dee3b4576b4588c7123e9fb8ec13cd0be55fe",
    "vout" : 0
}


Because it is locked, this transaction output will be protected against spending unless explicitly spent or unlocked. Now we will use it to start the exchange transaction,
specifying that we want 1.5 units of EUR (asset1) in exchange for this output:

createrawexchange "a4230175cfbe40a73ed21966406dee3b4576b4588c7123e9fb8ec13cd0be55fe"  0  '{"EUR":1.5}'

This will output a large hexadecimal blob of text that contains the raw transaction data representing the offer of exchange.

0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000


decoderawexchange 0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000


The output will show you exactly what is represented by this exchange offer in the offer and ask sections.
In addition, cancomplete should be true meaning that the second server has the assets required to complete the exchange.

 decoderawexchange 0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000
{"method":"decoderawexchange","params":["0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000"],"id":1,"chain_name":"chain1"}



___________________________________________________________________________________________________________
Now create a locked transaction output containing 1.5 units of asset1:


preparelockunspentfrom  "17WvENPL3G57Jo8a1rCzG2VHPsGdmo92jecqQn"  '{"EUR":1.5}'


{"method":"preparelockunspentfrom","params":["17WvENPL3G57Jo8a1rCzG2VHPsGdmo92jecqQn",{"EUR":1.50000000}],"id":1,"chain_name":"chain1"}

{
    "txid" : "dd3bc5e984ad6e1131a22a7eab6ae62ff942f65e4b7adfa276265741d8a151f1",
    "vout" : 0
}

Now we will complete the exchange transaction. (It would also be possible to create more complex multi-way exchanges by adding many different assets across multiple stages, but we’ll keep things simple here.) On the second server:

appendrawexchange [paste-hex-blob] a1b2... # '{"EUR":1.5}'
appendrawexchange 0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000 "dd3bc5e984ad6e1131a22a7eab6ae62ff942f65e4b7adfa276265741d8a151f1"  0  '{"EUR":1.5}'


The output should contain an even longer hexadecimal blob of text, alongside another field complete whose value is true.
This final hex blob is a raw transaction representing the completed exchange which can be transmitted to the network:

chain1: appendrawexchange 0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000 "dd3bc5e984ad6e1131a22a7eab6ae62ff942f65e4b7adfa276265741d8a151f1"  0  '{"EUR":1.5}'
{"method":"appendrawexchange","params":["0100000001fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0affffffff0100000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000","dd3bc5e984ad6e1131a22a7eab6ae62ff942f65e4b7adfa276265741d8a151f1",0,{"EUR":1.50000000}],"id":1,"chain_name":"chain1"}

{
    "hex" : "0100000002fe55bed03cc18efbe923718c58b476453bee6d406619d23ea740becf750123a4000000006b483045022100b67d100d7e4c8d1a96c6e572b8bd0e1cbb49a5d9042920d30f5c0d383655b6540220612d7ffefb51d7eef7b644f66b0933854a7d9e80391fae029fa908324bfac981832103d522bda386f2545b68705e14933e203019c579a9168e7f1e4c2faf1cd4c0ba0afffffffff151a1d841572676a2df7a4b5ef642f92fe66aab7e2aa231116ead84e9c53bdd000000006b48304502210089fb2a68ecac1ead05b6c50c17df319b5ebaffba2580eef65a5070a59d17a72402207345106bb41fb06e666d79dd527f5402dbeb5ab64c090228522caef712b64ff88321038f5ac1609ea6a2c5f4869de854349ce0822509f6ce6eb29b9dee11e468876172ffffffff0200000000000000003176a9140959bdde2d4c8bc89b10e955f8f1c653aba93f0188ac1673706b7110000000080100001e9396000000000000007500000000000000003176a9143035c8c7ee0f8774ff086efcb0ed36f7b44ac55c88ac1673706b7110000000080100001e9396000000000000007500000000",
    "complete" : false
Your appendrawexchange call used the wrong last parameter - it should be the currency wanted, not that offered.
...