Author Topic: Best way to tell if transaction is a deposit via RPC?  (Read 5178 times)

0 Members and 1 Guest are viewing this topic.

Offline vikram

Yes. Please be careful regardless, however. The current scanning and ledger construction code is honestly pretty bad (hence the rewrite), and the ledger entries may be inaccurate for certain types of transactions.

Can we have detail on exactly where the problems lie?

Can't really say; the current code is too complex to analyze. I would just manually test the particular types of transactions you are interested in; e.g.: TITAN transfers, BitAsset transfers with yield, etc.

Offline monsterer

Yes. Please be careful regardless, however. The current scanning and ledger construction code is honestly pretty bad (hence the rewrite), and the ledger entries may be inaccurate for certain types of transactions.

Can we have detail on exactly where the problems lie?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline vikram

This is very possible, but does not happen in practice yet since there are no good tools to do so. A transaction can pretty much have any arbitrary set of operations--this is why the transaction scanning (and thus history) is currently being rewritten (see https://github.com/BitShares/bitshares/issues/845) to treat transfers effectively as inputs and outputs--like in bitcoin.

Thanks vikram, that's good to know. For safety, do you suggest we parse every ledger entry inside each transaction as it's own 'micro' transaction with potential unique sender and receiver?

Yes. Please be careful regardless, however. The current scanning and ledger construction code is honestly pretty bad (hence the rewrite), and the ledger entries may be inaccurate for certain types of transactions.

Offline monsterer

This is very possible, but does not happen in practice yet since there are no good tools to do so. A transaction can pretty much have any arbitrary set of operations--this is why the transaction scanning (and thus history) is currently being rewritten (see https://github.com/BitShares/bitshares/issues/845) to treat transfers effectively as inputs and outputs--like in bitcoin.

Thanks vikram, that's good to know. For safety, do you suggest we parse every ledger entry inside each transaction as it's own 'micro' transaction with potential unique sender and receiver?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline vikram

Thanks... this should run against the server wallet so from account shouldnt matter... the hash makes sure i got the right tx.

But 'from_account' is the customer who's paying you, right? I'm just wondering if it's possible to have two different 'from_account's inside the ledger array?
There will be many diff from accounts.. U mean two different ppl paying for same thing? Well there is a hash too for that reason but if they know the hash then yes you can have someone else pay for you if you really want. The customer is not reequired to validate which account they are paying from when paying an order.

No, I mean within 1 transaction there is a ledger_entries array. Inside that array each entry has a 'from_account' field. That suggests to me that inside 1 transaction it might be possible to have several different people sending you assets. I just want clarity on whether this is possible or not.

This is very possible, but does not happen in practice yet since there are no good tools to do so. A transaction can pretty much have any arbitrary set of operations--this is why the transaction scanning (and thus history) is currently being rewritten (see https://github.com/BitShares/bitshares/issues/845) to treat transfers effectively as inputs and outputs--like in bitcoin.

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1335
    • View Profile
Yea I see.. if this is true we will have to loop through each tx to ensure we got all of the received coins we are looking for. I havent' seen this in my tests.. even sending multiple tx's within 10s so I can tentatively say that its 1 and not N inputs.

I don't know about you, but I wouldn't be comfortable with releasing software dealing with money without knowing answers like this *for certain* :)

Since there is no spec this is why we have to do codereviews with someone who can tell us right away aka bm.. i can look at the code too but cant be bothered to because  im not at the release and testing phase yet. You should come up with a verification test that will cover these cases to ensure its good.. thats my plan anyway.
Hired by blockchain | Developer
delegate: dev.sidhujag

Offline monsterer

Yea I see.. if this is true we will have to loop through each tx to ensure we got all of the received coins we are looking for. I havent' seen this in my tests.. even sending multiple tx's within 10s so I can tentatively say that its 1 and not N inputs.

I don't know about you, but I wouldn't be comfortable with releasing software dealing with money without knowing answers like this *for certain* :)
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1335
    • View Profile
Thanks... this should run against the server wallet so from account shouldnt matter... the hash makes sure i got the right tx.

But 'from_account' is the customer who's paying you, right? I'm just wondering if it's possible to have two different 'from_account's inside the ledger array?
There will be many diff from accounts.. U mean two different ppl paying for same thing? Well there is a hash too for that reason but if they know the hash then yes you can have someone else pay for you if you really want. The customer is not reequired to validate which account they are paying from when paying an order.

No, I mean within 1 transaction there is a ledger_entries array. Inside that array each entry has a 'from_account' field. That suggests to me that inside 1 transaction it might be possible to have several different people sending you assets. I just want clarity on whether this is possible or not.

Yea I see.. if this is true we will have to loop through each tx to ensure we got all of the received coins we are looking for. I havent' seen this in my tests.. even sending multiple tx's within 10s so I can tentatively say that its 1 and not N inputs.
Hired by blockchain | Developer
delegate: dev.sidhujag

Offline monsterer

Thanks... this should run against the server wallet so from account shouldnt matter... the hash makes sure i got the right tx.

But 'from_account' is the customer who's paying you, right? I'm just wondering if it's possible to have two different 'from_account's inside the ledger array?
There will be many diff from accounts.. U mean two different ppl paying for same thing? Well there is a hash too for that reason but if they know the hash then yes you can have someone else pay for you if you really want. The customer is not reequired to validate which account they are paying from when paying an order.

No, I mean within 1 transaction there is a ledger_entries array. Inside that array each entry has a 'from_account' field. That suggests to me that inside 1 transaction it might be possible to have several different people sending you assets. I just want clarity on whether this is possible or not.
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1335
    • View Profile
Thanks... this should run against the server wallet so from account shouldnt matter... the hash makes sure i got the right tx.

But 'from_account' is the customer who's paying you, right? I'm just wondering if it's possible to have two different 'from_account's inside the ledger array?
There will be many diff from accounts.. U mean two different ppl paying for same thing? Well there is a hash too for that reason but if they know the hash then yes you can have someone else pay for you if you really want. The customer is not reequired to validate which account they are paying from when paying an order.
Hired by blockchain | Developer
delegate: dev.sidhujag

Offline monsterer

Thanks... this should run against the server wallet so from account shouldnt matter... the hash makes sure i got the right tx.

But 'from_account' is the customer who's paying you, right? I'm just wondering if it's possible to have two different 'from_account's inside the ledger array?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1335
    • View Profile
Thanks... this should run against the server wallet so from account shouldnt matter... the hash makes sure i got the right tx.
Hired by blockchain | Developer
delegate: dev.sidhujag

Offline monsterer

Code: [Select]
      foreach($response['result'] as $txinfo)
      {
       
        // make sure the order was placed before it was paid on the blockchain, sanity check incase hash's match but tx is for wrong order.
        // also make sure this tx is confirmed on the blockchain before processing it
        if($txinfo['is_confirmed'] == true)
        {
        $timeStamp = $txinfo['timestamp'];
          $trxId = $txinfo['trx_id'];
          foreach($txinfo['ledger_entries'] as $tx) {

            $toaccount = $tx['to_account'];
     // could we get the asset by name aswell here? Another RPC call to get name
     $txSymbol = btsGetAssetNameById($tx['amount']['asset_id'], $rpcUser, $rpcPass, $rpcPort);
            $memo = $tx['memo'];
    if($txSymbol != $asset && !$demoMode)
        {
        continue;
        }
            // sanity check, tx to account should match your configured account in admin settings
            if($toaccount != $account)
            {
              continue;
            }
            // if this TX doesn't have the hash of the open order we are checking, skip this order
            if(strpos($memo, $orderEHASH) == FALSE)
            {
              continue;
            }
            $accumulatedAmountPaid += ($tx['amount']['amount']/100000);
          }
        }
      } 

There's a bug there - you're dividing by a magic number (100000) when you should be dividing by the precision of the asset.

:)

edit: I see you're assuming that all ledger entries have the same 'from_account', is that a safe assumption?
« Last Edit: December 11, 2014, 06:13:00 pm by monsterer »
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1335
    • View Profile
Inside the array of ledger_entries returned from wallet_account_transaction_history for 1 single transaction, can there be multiple different deposits?

This is my php code for the ecommerce plugins which will get the accumulated deposit amount based on a desired account (your account name):


Code: [Select]
      foreach($response['result'] as $txinfo)
      {
       
        // make sure the order was placed before it was paid on the blockchain, sanity check incase hash's match but tx is for wrong order.
        // also make sure this tx is confirmed on the blockchain before processing it
        if($txinfo['is_confirmed'] == true)
        {
        $timeStamp = $txinfo['timestamp'];
          $trxId = $txinfo['trx_id'];
          foreach($txinfo['ledger_entries'] as $tx) {

            $toaccount = $tx['to_account'];
     // could we get the asset by name aswell here? Another RPC call to get name
     $txSymbol = btsGetAssetNameById($tx['amount']['asset_id'], $rpcUser, $rpcPass, $rpcPort);
            $memo = $tx['memo'];
    if($txSymbol != $asset && !$demoMode)
        {
        continue;
        }
            // sanity check, tx to account should match your configured account in admin settings
            if($toaccount != $account)
            {
              continue;
            }
            // if this TX doesn't have the hash of the open order we are checking, skip this order
            if(strpos($memo, $orderEHASH) == FALSE)
            {
              continue;
            }
            $accumulatedAmountPaid += ($tx['amount']['amount']/100000);
          }
        }
      } 

It will also check the asset you are looking for aswell as an order hash.. but that isn't important. I just iterate over all transactions... so each tx will have a toaccount etc... there is only one entry per tx I believe.
« Last Edit: December 11, 2014, 05:45:27 pm by jsidhu »
Hired by blockchain | Developer
delegate: dev.sidhujag

Offline monsterer

Inside the array of ledger_entries returned from wallet_account_transaction_history for 1 single transaction, can there be multiple different deposits?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads