Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send ETH/ERC20 TX data #104

Closed
lukechilds opened this issue Jul 17, 2018 · 20 comments
Closed

Send ETH/ERC20 TX data #104

lukechilds opened this issue Jul 17, 2018 · 20 comments

Comments

@lukechilds
Copy link

lukechilds commented Jul 17, 2018

Currently in the update socket messages and the tradestatus completion method for ETH/ERC20 swaps we get the ETOMIC TXIDs/amounts but not the ETH/ERC20 values.

It would be great if you could expose the ETH/ERC20 TX data to us.

As an example, this is a current TX update object:

{
  "name": "bobdeposit",
  "coin": "ETOMIC",
  "tx": "0100000001581946dcc0ca9e473d17a7199e2104678d39436dafc25d4002db641039e3cc34010000006b483045022100c311c0efe7ab3665cd8ada46e610e58c262ed079225a108776d171992047c5a602204aa3b22fcefa5c3ddbb2766a023577588daad88a02a13a2a42879e14a755a00e012102f047e14e64689a3464b62d7ed551f5228f7c6d38f61980ab89ace38525fe199effffffff02efa4b4060000000017a9142be18265142ed155d7df201f187ee7642a9ee19287a74f45b9000000001976a914719adc7ec7ad318b2ebfcc500822d2483ab8f8d688acd70f4e5b",
  "txid": "b856c6d7fc0e4bdc89dcafc0e1607fef1f4070e6d7a028226d8c52038e413d87",
  "Bdeposit": "0x2be18265142ed155d7df201f187ee7642a9ee192",
  "expiration": 1531842519,
  "uuid": "413403a1a1907bdf18cd0fbc4ebcfeb8850bb7af640750751e80e29626c7dd73",
  "iambob": 0,
  "bobcoin": "MYTH",
  "bobtomic": "0x277ab4b9dde09a8e710fd755deeb9d0d9532d047",
  "etomicsrc": "0xe675e3bed50682297adc795bf7756e618c32a8f3",
  "bobDepositEthTx": "0xf70a6e90c7cf854cb36df488e733cc6ccea554b8465932c483a0e8ea2420311a",
  "aliceRealSat": "0",
  "bobRealSat": "972872033",
  "alicecoin": "KMD",
  "etomicdest": "0x7b0f414f040f59a743716027f8a24a37dbe1d16f",
  "lock": 0,
  "amount": 1.12502,
  "Apayment": "bTNHjB86Ex1W4m9DEEXUrfppbAcxmsWRHB",
  "redeem": "6304d70f4e5bb17582012088a914891324366afabe2922e518b5c5088a412f9cf1f4882102581cc589fd63fe464a5a60e337f0214e4fcad747c7ecfbb7ecaab84d6f47c83eac6782012088a91460283920463fe8fb6b8f0f0b84097805afab696a882103fb4bea54e3ce957466917e16a5b034dd556fdf4ea971db49593b0b44523d39b7ac68",
  "method": "update",
  "update": "bobdeposit",
  "requestid": 1980583534,
  "quoteid": 2269013680
}

I see there is bobDepositEthTx for the ETH TXID and bobRealSat.

However it would be better if bobDepositEthTx could just be exposed as something like txidEth so we can aways use that over txid if it exists, then we don't have to manually search for the ETH TXID property for each TX type e.g bobDepositEthTx, bobPaymentEthTx etc.

Also bobRealSat appears to be denoted in "satoshis" which doesn't really make sense for ETH/ERC20. This could cause issues if the token has a non standard decimal amount. It would be great if mm could calculate the value based on it's internal ERC20 decimal value and just expose amountEth.

With these solutions we can just rely on using txidEth and amountEth if they exist, if not, fallback to txid and amount.

We also regenerate all trade data from the completed tradestatus message.

An example:

{
  "uuid": "413403a1a1907bdf18cd0fbc4ebcfeb8850bb7af640750751e80e29626c7dd73",
  "expiration": 1531842519,
  "tradeid": 2724183059,
  "requestid": 1980583534,
  "quoteid": 2269013680,
  "iambob": 0,
  "Bgui": "",
  "Agui": "hyperdex",
  "gui": "hyperdex",
  "bob": "MYTH",
  "bobtomic": "0x277ab4b9dde09a8e710fd755deeb9d0d9532d047",
  "etomicsrc": "0xe675e3bed50682297adc795bf7756e618c32a8f3",
  "srcamount": 9.72872033,
  "bobtxfee": 0.00001,
  "alice": "KMD",
  "etomicdest": "0x7b0f414f040f59a743716027f8a24a37dbe1d16f",
  "destamount": 1.00008999,
  "alicetxfee": 0.00001,
  "aliceid": "6016495696859496449",
  "result": "success",
  "status": "finished",
  "finishtime": 1531827408,
  "bobdeposit": "b856c6d7fc0e4bdc89dcafc0e1607fef1f4070e6d7a028226d8c52038e413d87",
  "alicepayment": "c1f2fc2d3f04d114b2369f779b2998d27843f97fea66cf853cdfc9c0c8663dc1",
  "bobpayment": "76b77af9951e12d46f009aa7c97378e9ca76961860aed3271b06adb889b818fb",
  "paymentspent": "e53dcd6f1ae43e8a0404263ec67e552fc2f699ba86a0620b446c924d8837cd0e",
  "Apaymentspent": "0000000000000000000000000000000000000000000000000000000000000000",
  "depositspent": "0000000000000000000000000000000000000000000000000000000000000000",
  "alicedexfee": "3229097506b4baab932412db463441268eea26c37c1c4571aedc3bda07f21a98",
  "method": "tradestatus",
  "values": [
    1.00000999,
    0,
    1.00002,
    1.00011,
    1.12502,
    0,
    0.00128711,
    0,
    0,
    0,
    0
  ],
  "sentflags": [
    "alicespend",
    "bobpayment",
    "alicepayment",
    "bobdeposit",
    "myfee"
  ]
}

This is to ensure we have correct trade data if the mm node went offline, restarted, was reverted etc. We can currently completely rebuild a BTC protocol trade with this data but not an ETH/ERC20 trade.

We need ETH/ERC20 TXIDs and amounts included to be able to do this, currently we only have ETOMIC.

@artemii235
Copy link
Member

@lukechilds
Hi, I've made changes to WS events, please check if they look how you want:

  1. Payment updates txid and amount are replaced with ETH info:
{
    "name": "alicepayment",
    "tx": "0100000001f8bf547f81d2c6f6fe14bdbc45abd5b6bfc0e5245bee1a08cb96358b5fa4f348010000006b483045022100bcab6d5a89dcce6c519d73ae4d90589a2fb165769d37676d7505208063dfce9902203385d7fd20efc1c6b98cf7100f401379561048ad5b9a54bd62b0c4452b523acb012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff02cfe8f5050000000017a9140ab3ec990bf28508044165d3d4856d7d64381efa876a6ca01d000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac00000000",
    "Bdeposit": "0x43f5d8672c0c22a29c12d599d8f7881e4c959c9c",
    "expiration": 1532084277,
    "uuid": "4526cafddf6ec3bf6c55953f2a53e1069cc9e4bf9828bd5207512ca304415373",
    "iambob": 0,
    "bobcoin": "JST",
    "bobtomic": "0xc0eb7aed740e1796992a08962c15661bdeb58003",
    "etomicsrc": "0x4b2d0d6c2c785217457b69b922a2a9cea98f71e9",
    "aliceFeeEthTx": "0x6c3dc5b44d169fea23a37465159660500ffadbb1f94af39a8046e7e57d5244c4",
    "bobDepositEthTx": "0xbc18b3e3bd5618eac6111f6792028ea2b8ac5b7c2169e4408e602dd9c79d58a5",
    "alicePaymentEthTx": "0x51287423c84f1ef13188fd16b6f919dd4447f42dd5670ce50c85d5747ad143b1",
    "aliceRealSat": "10009000",
    "bobRealSat": "9735184",
    "alicecoin": "ETH",
    "alicetomic": "0x0000000000000000000000000000000000000000",
    "etomicdest": "0xbab36286672fbdc7b250804bf6d14be0df69fa29",
    "lock": 0,
    "trigger": "a58af04288edc3055ae8824920afbefa67148cb0ff7dab9a836274fd5b4e9042",
    "Apayment": "0x0ab3ec990bf28508044165d3d4856d7d64381efa",
    "redeem": "522102af4455fcaaf6679e5c16d80d5b3b4e57497c929f64c1565a6fae04d145bb1252210375e03644a810f25d7c1d7d63876f1c482c1482205c65f554831b5a499d35ff3252ae",
    "txid": "0x51287423c84f1ef13188fd16b6f919dd4447f42dd5670ce50c85d5747ad143b1",
    "amount": 0.10009,
    "coin": "ETH",
    "method": "update",
    "update": "alicepayment",
    "requestid": 3289729978,
    "quoteid": 2613152108
  }
  1. Tradestatus has additional object eth_info:
    "eth_info": {
      "alicefee": {
        "txid": "0x6c3dc5b44d169fea23a37465159660500ffadbb1f94af39a8046e7e57d5244c4",
        "amount": 0.00012881
      },
      "alicepayment": {
        "txid": "0x51287423c84f1ef13188fd16b6f919dd4447f42dd5670ce50c85d5747ad143b1",
        "amount": 0.10009
      },
      "bobdeposit": {
        "txid": "0xbc18b3e3bd5618eac6111f6792028ea2b8ac5b7c2169e4408e602dd9c79d58a5",
        "amount": 0.10952082
      },
      "bobpayment": {
        "txid": "0x587d09ac16902e31d7a05a745a3c496ecbbddd47745da69303b2da7a12bcee9e",
        "amount": 0.09735184
      }
    }
  1. Do you need spending transactions ids from ETH side on tradestatus?

@lukechilds
Copy link
Author

Thanks @artemii235, this looks perfect!

  1. Do you need spending transactions ids from ETH side on tradestatus?

Not too sure what you mean here?

@artemii235
Copy link
Member

@lukechilds
Tradestatus contains spends of payments/deposit (e.g. Alice spent Bob payment tx):

    "paymentspent": "a0d6cca269cf18a8dd5bf51b2e50a3384ae611a69aded38bdf06acdee8a0b7ea",
    "Apaymentspent": "0000000000000000000000000000000000000000000000000000000000000000",
    "depositspent": "0000000000000000000000000000000000000000000000000000000000000000",

Do you need this info for ETH side?

@lukechilds
Copy link
Author

Oh right, missed that, yeah we need that too to show the final TX in the chain.

artemii235 added a commit that referenced this issue Jul 23, 2018
artemii235 added a commit that referenced this issue Jul 23, 2018
#97 Check ETOMIC balance before faucet. #104 Expose ETH data on WS.
@artemii235
Copy link
Member

@lukechilds https://github.com/artemii235/SuperNET/releases/tag/v1.0.329 - release was published, please test it and let me know result.

@lukechilds
Copy link
Author

Thanks!

Testing now.

@lukechilds
Copy link
Author

Looking good artem, but looks like it still needs a tiny tweak.

I think there should be an alicespend property in eth_info:

{
  "uuid": "2418498a876dba5fad5cf77af38273136621149ee2302c14b39043a5c5ba2753",
  "expiration": 1532466810,
  "tradeid": 10845859,
  "requestid": 551717757,
  "quoteid": 1186618386,
  "iambob": 0,
  "Bgui": "",
  "Agui": "hyperdex",
  "gui": "hyperdex",
  "bob": "MYTH",
  "bobtomic": "0x277ab4b9dde09a8e710fd755deeb9d0d9532d047",
  "etomicsrc": "0xe675e3bed50682297adc795bf7756e618c32a8f3",
  "srcamount": 9.63503266,
  "bobtxfee": 0.00001,
  "alice": "KMD",
  "etomicdest": "0x30bd6328e9495be74efa11bb25b5a3f0506e85e2",
  "destamount": 1.00008999,
  "alicetxfee": 0.00001,
  "aliceid": "606182714381762561",
  "result": "success",
  "status": "finished",
  "finishtime": 1532451690,
  "bobdeposit": "f282cccaff18c094be2bfb7b37ba8f90439cca50bc7f866200bebfe8ca09a101",
  "alicepayment": "01b55e758128d8ce6eb58f581bdb950e5e0e5abd1408a2561f3efff5573f3f91",
  "bobpayment": "753a94db075f9f7dbfc858ed38755d10a6d8400cf5c1312935752d4e55e510e4",
  "paymentspent": "56d0b4ccd8c2d3359ed9ee40fcfd9bb52bf34f4acc3c3d7371ceca8b9edd8db4",
  "Apaymentspent": "0000000000000000000000000000000000000000000000000000000000000000",
  "depositspent": "0000000000000000000000000000000000000000000000000000000000000000",
  "alicedexfee": "4099ae03cf22cae7702ccabde23f4eac88dddee10ed95dd82ec366cbf48ae8e4",
  "method": "tradestatus",
  "eth_info": {
    "bobpaymentspent": {
      "txid": "0x437a73b4562f61b0249ba0a141ecd813b65c41e36ec017aece2ebebfc52d6a53",
      "amount": 9.63503266
    },
    "bobpayment": {
      "txid": "0x83f47fbc74a81b07a35187e9180d13cb302059a857d2f577cbde2a68d967fca8",
      "amount": 9.63503266
    },
    "bobdeposit": {
      "txid": "0x25fda9c1c4153b7c8dc6ca919c212fa4797ca1f2ada65e747d9ce4d99ab33a8a",
      "amount": 10.83941174
    }
  },
  "values": [
    1.00000999,
    0,
    1.00002,
    1.00011,
    1.12502,
    0,
    0.00128711,
    0,
    0,
    0,
    0
  ],
  "sentflags": [
    "alicespend",
    "bobpayment",
    "alicepayment",
    "bobdeposit",
    "myfee"
  ]
}

It comes through correctly in the update messages, but it's missing in the final tradestatus message.

@lukechilds
Copy link
Author

lukechilds commented Jul 24, 2018

An alternative, and possibly neater solution would be to just expose a txChain array that just lists the TXs in order with the correct amounts and TXIDs, regardless of if it's a BTC protocol coin or ETH/ERC20 token.

Something like:

[
  {
    "stage": "myfee",
    "coin": "KMD",
    "txid": "4099ae03cf22cae7702ccabde23f4eac88dddee10ed95dd82ec366cbf48ae8e4",
    "amount": 0.00128711
  },
  {
    "stage": "bobdeposit",
    "coin": "MYTH",
    "txid": "0x25fda9c1c4153b7c8dc6ca919c212fa4797ca1f2ada65e747d9ce4d99ab33a8a",
    "amount": 10.83941174
  },
  {
    "stage": "alicepayment",
    "coin": "KMD",
    "txid": "01b55e758128d8ce6eb58f581bdb950e5e0e5abd1408a2561f3efff5573f3f91",
    "amount": 1.00011
  },
  {
    "stage": "bobpayment",
    "coin": "MYTH",
    "txid": "0x83f47fbc74a81b07a35187e9180d13cb302059a857d2f577cbde2a68d967fca8",
    "amount": 9.63503266
  },
  {
    "stage": "alicespend",
    "coin": "MYTH",
		"txid": "0x83f47fbc74a81b07a35187e9180d13cb302059a857d2f577cbde2a68d967fca8",
    "amount": 9.63503266
  }
]

Then that can be used for all trades without having to do lots of checks of whether it's an etomic swap and if so which coins are etomic and get different values for each.

@lukechilds
Copy link
Author

We also needs to show aliceclaim and alicereclaim data for non standard swaps. Not sure if you're already exposing that as I haven't managed to trigger a failed swap yet.

@artemii235
Copy link
Member

@lukechilds
Hi, as I understand alicespend is Alice spending Bob payment, it is same as

    "bobpaymentspent": {
      "txid": "0x437a73b4562f61b0249ba0a141ecd813b65c41e36ec017aece2ebebfc52d6a53",
      "amount": 9.63503266
    },

You can see aliceclaim in case Bob side is ETH/ERC20 as bobdepositspent in eth_info.

alicereclaim will be alicepaymentspent in case Alice is ETH/ERC20 and Alice reclaimed payment. Please let me know if this naming is confusing.

txChain looks like good idea. Do you want it to replace eth_info?

@lukechilds
Copy link
Author

lukechilds commented Jul 25, 2018

Hi Artem, ah sorry, I missed those, looks like everything is there then.

So I should be able to implement everything with what we've got.

But yeah, if you could refactor into txChain that would be tons simpler.

At the moment we are getting the currency, stage, txid and value for each TX. And they have different naming conventions for the stage depending on which part of the code you're in and what other swap conditions are active.

e.g:

myfee == alicefee == alicedexfee
bobdeposit
alicepayment
bobpayment
alicespend == paymentspent == bobpaymentspent
aliceclaim == depositspent == bobdepositspent
alicereclaim == Apaymentspent == alicepaymentspent

These are all the same values and we have a load of spaghetti code to pluck the right values out depending on the situation.

It would be great if you could replace this with a simple txChain array we can just loop through!

If you could keep the names consistent with the ones in message.sentflags that would be great too.

e.g:

"sentflags": [
  "alicespend",
  "bobpayment",
  "alicepayment",
  "bobdeposit",
  "myfee"
]

Thanks!

@artemii235
Copy link
Member

@lukechilds Ok, I will do it tomorrow and publish a new release.

@lukechilds
Copy link
Author

Can't wait, thanks @artemii235!

@lukechilds
Copy link
Author

lukechilds commented Jul 26, 2018

Hey @artemii235 I noticed there is a new release (v1.0.338).

Did you manage to get these tweaks in?

@artemii235
Copy link
Member

@lukechilds Hi, excuse me, not yet. That release is automatic PR from jl777 dev branch. I'll finish this task today - new release will be created.

artemii235 added a commit that referenced this issue Jul 27, 2018
#104 #108. Add txChain to tradestatus. Do not wait for bob deposit in case of error.
@artemii235
Copy link
Member

@lukechilds https://github.com/artemii235/SuperNET/releases/tag/v1.0.342 - done, release is published, please test and let me know results.

@lukechilds
Copy link
Author

Great, thanks @artemii235! Will test today.

@lukechilds
Copy link
Author

@artemii235 Thanks, tested this looks absolutely perfect!

Just to clarify:

  1. Can we rely on the TXs in the txChain array being in order?
  2. Will aliceclaim and alicereclaim appear in the txChain?

@artemii235
Copy link
Member

@lukechilds
Hi,

  1. Yes, transaction will always appear in order of txnames:
    https://github.com/artemii235/SuperNET/blob/master/iguana/exchanges/LP_include.h#L271
  2. Yes, if Alice reclaims her payment the tx record will be added to txChain in appropriate order. Same for alicereclaim (when Alice claims bob deposit).

@lukechilds
Copy link
Author

Perfect!

Thanks so much for this Artem, it's made our lives a hell of a lot easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants