Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: Best way to tell if transaction is a deposit via RPC?  (Read 710 times)

0 Members and 1 Guest are viewing this topic.

Offline monsterer

Best way to tell if transaction is a deposit via RPC?
« on: December 09, 2014, 11:18:46 AM »

I'm trying to find the best way to determine whether a given transaction is a deposit.

Using wallet_account_transaction_history, we have a structure returned which contains multiple ledger entries and I'm not sure if you could have both a deposit and a withdraw inside that array?

Using blockchain_get_transaction we have an array of 'operations' inside the 'trx' field which typically contains both withdraw_op_type and deposit_op_type.

Is there an easy way to tell whether a given transaction is a deposit? Just some clarity on the subject would be great :)

Cheers, Paul.
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline bytemaster

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #1 on: December 09, 2014, 01:28:23 PM »
I'm trying to find the best way to determine whether a given transaction is a deposit.

Using wallet_account_transaction_history, we have a structure returned which contains multiple ledger entries and I'm not sure if you could have both a deposit and a withdraw inside that array?

Using blockchain_get_transaction we have an array of 'operations' inside the 'trx' field which typically contains both withdraw_op_type and deposit_op_type.

Is there an easy way to tell whether a given transaction is a deposit? Just some clarity on the subject would be great :)

Cheers, Paul.

It is of course a matter of perspective, for one user it is a deposit the other it is a withdraw.  For what you are doing it is probably safe to simply check the owner address of the claim_with_signature deposit operation belongs to your account:

wallet_account_list_public_keys ACCOUNT_NAME
wallet_dump_private_key BTS_ADDRESS


For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12280
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: Best way to tell if transaction is a deposit via RPC?
« Reply #2 on: December 09, 2014, 01:39:20 PM »
Isnt there a call like
wallet_verify_titan_tx .. or so?
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1337
    • View Profile
Re: Best way to tell if transaction is a deposit via RPC?
« Reply #3 on: December 09, 2014, 06:21:33 PM »
the toaccount of wallet_account_transaction_history will tell you it was sent to you (thus deposit). This list will only update if wallet is unlocked.
« Last Edit: December 09, 2014, 06:24:17 PM by jsidhu »
Hired by blockchain | Developer
delegate: dev.sidhujag

Offline monsterer

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #4 on: December 09, 2014, 08:10:14 PM »
the toaccount of wallet_account_transaction_history will tell you it was sent to you (thus deposit). This list will only update if wallet is unlocked.

If you register your own account the to and from are both you inside the transaction, so this rule doesn't quite work :)
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline vikram

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #5 on: December 09, 2014, 08:35:56 PM »
Depends what you mean by deposit?

The individual operations you see from something like blockchain_get_transaction represent exactly what happened to the DAC.

Offline monsterer

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #6 on: December 09, 2014, 08:52:38 PM »
Depends what you mean by deposit?

The individual operations you see from something like blockchain_get_transaction represent exactly what happened to the DAC.

My difficulty was in understanding which was a deposit to my account (deposit from their account) and which was a withdraw from my account (withdraw from their account).
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline Xeldal

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #7 on: December 09, 2014, 09:23:45 PM »
the toaccount of wallet_account_transaction_history will tell you it was sent to you (thus deposit). This list will only update if wallet is unlocked.
+5%  I must not understand the problem, because this^ seems to answer it as far as I can tell.


the toaccount of wallet_account_transaction_history will tell you it was sent to you (thus deposit). This list will only update if wallet is unlocked.

If you register your own account the to and from are both you inside the transaction, so this rule doesn't quite work :)
I think you could say this still applies, the registration is a fee, and is burned.  The transaction is all fees and zero is deposited in the to_account

Offline monsterer

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #8 on: December 11, 2014, 04:22:22 PM »
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

Offline jsidhu

  • Hero Member
  • *****
  • Posts: 1337
    • View Profile
Re: Best way to tell if transaction is a deposit via RPC?
« Reply #9 on: December 11, 2014, 05:40:50 PM »
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

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #10 on: December 11, 2014, 06:09:40 PM »
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: 1337
    • View Profile
Re: Best way to tell if transaction is a deposit via RPC?
« Reply #11 on: December 12, 2014, 02:49:34 AM »
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

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #12 on: December 12, 2014, 10:25:28 AM »
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: 1337
    • View Profile
Re: Best way to tell if transaction is a deposit via RPC?
« Reply #13 on: December 12, 2014, 05:11:06 PM »
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

Re: Best way to tell if transaction is a deposit via RPC?
« Reply #14 on: December 12, 2014, 10:32:05 PM »
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

 

Google+