Author Topic: Automatically refunding transactions sent from unregistered accounts?  (Read 4044 times)

0 Members and 1 Guest are viewing this topic.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc

Offline monsterer

I noticed that the transaction history does not show transactions that are send to an address directly instead of a TITAN address ... not sure if this is fixed.
You could check this by comparing your "balance" before and after your "refund"

Oh, right you are! Thank you! Yes, ok that's great - so this is working, but its just not shown in the client. I guess this is a bug to be fixed in the client?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I noticed that the transaction history does not show transactions that are send to an address directly instead of a TITAN address ... not sure if this is fixed.
You could check this by comparing your "balance" before and after your "refund"

Offline monsterer

toast, I don't suppose you have a code reference for how you do sharedrops this way? I'm having trouble getting it to work - the funds are sent ok, but never arrive in the recipient's wallet.

psudocode:

Code: [Select]
BitsharesTransaction t = m_bitshares.BlockchainGetTransaction(depositId);

// get the sender's address from the balance id, from the first op of type withdraw_op_type
BitsharesOperation op = t.trx.operations.First(o => o.type == BitsharesTransactionOp.withdraw_op_type);

BitsharesBalanceRecord balance = m_bitshares.GetBalance(op.data.balance_id);
string senderAddress = balance.condition.data.owner;

response = m_bitshares.WalletTransferToAddress(amount, m_asset.symbol, m_bitsharesAccount, senderAddress, memo);
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline monsterer

Do you want to refund the exact amount to each input? I'd just pick one arbitrarily since you know they have access to both, like how we credited AGS.

No, all I want is for the transaction to be fully refunded to the sender account - looks like I can do this now, great, thanks! :)
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Oh ... so the balanceids is sth. else ... how is the balance id derived? Would sending funds to the balance id also work?

Balance ID is a hash of the withdraw condition. If you sent to it, it would be unrecoverable. Maybe we ought to check that there's not a balance ID equal to the "address" you are sending to to prevent it.
Learnd sth ... thx for the insights

Offline toast

  • Hero Member
  • *****
  • Posts: 4001
    • View Profile
  • BitShares: nikolai
Get the balance record from the balance id:  get_balance BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng

But there are multiple balance id's per transaction? In my case I have two of them.

Quote
Transfer to the address in the withdraw condition

Is this not the same as the owner field I have inside the main transaction?

Code: [Select]
"condition": {
              "asset_id": 0,
              "slate_id": 0,
              "type": "withdraw_signature_type",
              "data": {
                "owner": "BTS82mTkM4nZLBUs7FZBux3zDV4TvdsUcdYR",
                "memo": {
                  "one_time_key": "BTS7P2Ped3mpLeQfuiH8HE9Smoy6cHom1YNNzEqgDg5EmPFPLMDrn",
                  "encrypted_memo_data": "bd8f6702454b0e04284fedcbaf7e4859603a2df1c32f83909ac88e95fc5d13ffb1d71b2f92cec504ef3599c76bd1a7f59e13a535dbed9f96489c906ef131fec3"
                }
              }
            }

?

If there are multiple balances that just means someone merged two inputs. Do you want to refund the exact amount to each input? I'd just pick one arbitrarily since you know they have access to both, like how we credited AGS.

The owner shown in the the raw transaction is in the DEPOSITED balance - you wouldn't be refunding anything but just sending it to yourself.
Do not use this post as information for making any important decisions. The only agreements I ever make are informal and non-binding. Take the same precautions as when dealing with a compromised account, scammer, sockpuppet, etc.

Offline monsterer

Get the balance record from the balance id:  get_balance BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng

But there are multiple balance id's per transaction? In my case I have two of them.

Quote
Transfer to the address in the withdraw condition

Is this not the same as the owner field I have inside the main transaction?

Code: [Select]
"condition": {
              "asset_id": 0,
              "slate_id": 0,
              "type": "withdraw_signature_type",
              "data": {
                "owner": "BTS82mTkM4nZLBUs7FZBux3zDV4TvdsUcdYR",
                "memo": {
                  "one_time_key": "BTS7P2Ped3mpLeQfuiH8HE9Smoy6cHom1YNNzEqgDg5EmPFPLMDrn",
                  "encrypted_memo_data": "bd8f6702454b0e04284fedcbaf7e4859603a2df1c32f83909ac88e95fc5d13ffb1d71b2f92cec504ef3599c76bd1a7f59e13a535dbed9f96489c906ef131fec3"
                }
              }
            }

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

Offline toast

  • Hero Member
  • *****
  • Posts: 4001
    • View Profile
  • BitShares: nikolai
Oh ... so the balanceids is sth. else ... how is the balance id derived? Would sending funds to the balance id also work?

Balance ID is a hash of the withdraw condition. If you sent to it, it would be unrecoverable. Maybe we ought to check that there's not a balance ID equal to the "address" you are sending to to prevent it.
Do not use this post as information for making any important decisions. The only agreements I ever make are informal and non-binding. Take the same precautions as when dealing with a compromised account, scammer, sockpuppet, etc.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Oh ... so the balanceids is sth. else ... how is the balance id derived? Would sending funds to the balance id also work?

Offline toast

  • Hero Member
  • *****
  • Posts: 4001
    • View Profile
  • BitShares: nikolai
Get the balance record from the balance id:  get_balance BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng
{
  "condition": {
    "asset_id": 0,
    "slate_id": 0,
    "type": "withdraw_signature_type",
    "data": {
      "owner": "BTSKrYCvm4RcLNqekPiTXHzcrVkxejwAdhfL",
      "memo": null
    }
  },
  "balance": 0,
  "restricted_owner": null,
  "snapshot_info": null,
  "deposit_date": "2015-01-13T08:42:00",
  "last_update": "2015-01-14T08:46:30"
}


Transfer to the address in the withdraw condition

wallet_transfer_to_address blah blah blah BTSKrYCvm4RcLNqekPiTXHzcrVkxejwAdhfL
Do not use this post as information for making any important decisions. The only agreements I ever make are informal and non-binding. Take the same precautions as when dealing with a compromised account, scammer, sockpuppet, etc.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Just send it back to one of the balanceids or addresses in the withdraw operation ... give it a try .. should work nicely

Offline monsterer

Thanks for the detail.

I'm still not sure if any of that helps me to figure out how to refund a deposit from an unregistered account in a single transaction, though?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Here's the whole transaction for reference:

Code: [Select]
[
  "d888ac6e13fe60d9cdf74c5752b8a4a3f827f4a2",{
    "trx": {
      "expiration": "2015-01-14T09:46:35",
      "delegate_slate_id": null,
      "operations": [{
          "type": "deposit_op_type",
          "data": {
            "amount": 10000,
            "condition": {
              "asset_id": 0,
              "slate_id": 0,
              "type": "withdraw_signature_type",
              "data": {
                "owner": "BTS82mTkM4nZLBUs7FZBux3zDV4TvdsUcdYR",
                "memo": {
                  "one_time_key": "BTS7P2Ped3mpLeQfuiH8HE9Smoy6cHom1YNNzEqgDg5EmPFPLMDrn",
                  "encrypted_memo_data": "bd8f6702454b0e04284fedcbaf7e4859603a2df1c32f83909ac88e95fc5d13ffb1d71b2f92cec504ef3599c76bd1a7f59e13a535dbed9f96489c906ef131fec3"
                }
              }
            }
          }
        },{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng",
            "amount": 10000,
            "claim_input_data": ""
          }
        },{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTSASw7dDN1u3VaSNw5SNYk1WNN9uKBWZoDU",
            "amount": 10000,
            "claim_input_data": ""
          }
        }
      ],
      "signatures": [
        "1f15c6e8076429d5c6a26eb314a2fa0aba1a0650f9af592abd52b25c9377383b4210f01c8c0c18ce1029d311822817dfcea9ceff1fee05f4ad31a5d62bdda6198a",
        "1f6868afae9b4f8d4d7566ec95d71760e695fdd8d232bf0ca3c12b2c764504ec35152a9df4cba00afe46089141bcf5064d28aac6aaf5e36ec41b90f606b0fe83bf"
      ]
    },
    "current_op_index": 3,
    "signed_keys": [],
    "validation_error": null,
    "provided_deposits": [[
        "BTSKdc8euepN6bZ32K5sdvvQQA7GD3udToN7",{
          "amount": 10000,
          "asset_id": 0
        }
      ]
    ],
    "deposits": [[
        0,{
          "amount": 10000,
          "asset_id": 0
        }
      ]
    ],
    "withdraws": [[
        0,{
          "amount": 20000,
          "asset_id": 0
        }
      ]
    ],
    "yield": [],
    "deltas": [[
        0,{
          "amount": 10000,
          "asset_id": 0
        }
      ],[
        1,{
          "amount": -10000,
          "asset_id": 0
        }
      ],[
        2,{
          "amount": -10000,
          "asset_id": 0
        }
      ]
    ],
    "required_fees": {
      "amount": 0,
      "asset_id": 0
    },
    "alt_fees_paid": {
      "amount": 0,
      "asset_id": 0
    },
    "balance": [[
        0,
        10000
      ]
    ],
    "net_delegate_votes": [],
    "chain_location": {
      "block_num": 1520903,
      "trx_num": 0
    }
  }
]

As you can see, balance_id only occurs in the operations array and there are two of them.

deposit_op_type contains a single owner field, is that what you are talking about?


The owner is the receiver (at least one address that was derived from the registered account name) .. if you were the receiver you could figure out if that was your address (read: if you could derive the private key for it) by using the date in the memo (the "one_time_key" - which is a public key).
So: owner -> receiver of the funds
you can also see this as the owner is in the "deposit_op_type" operation and the withdraw condition says "withdraw_signature_type" .. so .. however holds the private key to "the owner" literally owns the shares/coins/assets

The "withdraw_op_type" operations are used to address the "inputs" of the transaction .. those are the operations that have to be "signed" (see signatures - there are two of them) ..
those balance_ids hold transactions that can be redeemed using signatures (so have been sent there with transactions with conditions "withdraw_signature_type")

To test this:
Just take one of your outgoing transactions .. figure out the balance_id and send some funds to that address using wallet_transfer_asset_to_address (or so) ..

Offline monsterer

Here's the whole transaction for reference:

Code: [Select]
[
  "d888ac6e13fe60d9cdf74c5752b8a4a3f827f4a2",{
    "trx": {
      "expiration": "2015-01-14T09:46:35",
      "delegate_slate_id": null,
      "operations": [{
          "type": "deposit_op_type",
          "data": {
            "amount": 10000,
            "condition": {
              "asset_id": 0,
              "slate_id": 0,
              "type": "withdraw_signature_type",
              "data": {
                "owner": "BTS82mTkM4nZLBUs7FZBux3zDV4TvdsUcdYR",
                "memo": {
                  "one_time_key": "BTS7P2Ped3mpLeQfuiH8HE9Smoy6cHom1YNNzEqgDg5EmPFPLMDrn",
                  "encrypted_memo_data": "bd8f6702454b0e04284fedcbaf7e4859603a2df1c32f83909ac88e95fc5d13ffb1d71b2f92cec504ef3599c76bd1a7f59e13a535dbed9f96489c906ef131fec3"
                }
              }
            }
          }
        },{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng",
            "amount": 10000,
            "claim_input_data": ""
          }
        },{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTSASw7dDN1u3VaSNw5SNYk1WNN9uKBWZoDU",
            "amount": 10000,
            "claim_input_data": ""
          }
        }
      ],
      "signatures": [
        "1f15c6e8076429d5c6a26eb314a2fa0aba1a0650f9af592abd52b25c9377383b4210f01c8c0c18ce1029d311822817dfcea9ceff1fee05f4ad31a5d62bdda6198a",
        "1f6868afae9b4f8d4d7566ec95d71760e695fdd8d232bf0ca3c12b2c764504ec35152a9df4cba00afe46089141bcf5064d28aac6aaf5e36ec41b90f606b0fe83bf"
      ]
    },
    "current_op_index": 3,
    "signed_keys": [],
    "validation_error": null,
    "provided_deposits": [[
        "BTSKdc8euepN6bZ32K5sdvvQQA7GD3udToN7",{
          "amount": 10000,
          "asset_id": 0
        }
      ]
    ],
    "deposits": [[
        0,{
          "amount": 10000,
          "asset_id": 0
        }
      ]
    ],
    "withdraws": [[
        0,{
          "amount": 20000,
          "asset_id": 0
        }
      ]
    ],
    "yield": [],
    "deltas": [[
        0,{
          "amount": 10000,
          "asset_id": 0
        }
      ],[
        1,{
          "amount": -10000,
          "asset_id": 0
        }
      ],[
        2,{
          "amount": -10000,
          "asset_id": 0
        }
      ]
    ],
    "required_fees": {
      "amount": 0,
      "asset_id": 0
    },
    "alt_fees_paid": {
      "amount": 0,
      "asset_id": 0
    },
    "balance": [[
        0,
        10000
      ]
    ],
    "net_delegate_votes": [],
    "chain_location": {
      "block_num": 1520903,
      "trx_num": 0
    }
  }
]

As you can see, balance_id only occurs in the operations array and there are two of them.

deposit_op_type contains a single owner field, is that what you are talking about?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
every withdraw tx uses a balance_id (address) that holds funds to withdraw from ..
you can just send the funds there and the client should catch up that transaction ..
there's no need to 'identify' the unregistered account .. just refund to the address (balance_id) you received the money from ..

Are there any docs on what all these fields mean? I had assumed balance_id was like a UTXO and that 'from_account' was the sender.

Take a look at part of this deposit:

Code: [Select]
{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng",
            "amount": 10000,
            "claim_input_data": ""
          }
        },{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTSASw7dDN1u3VaSNw5SNYk1WNN9uKBWZoDU",
            "amount": 10000,
            "claim_input_data": ""
          }
        }

As you can see there are two balance_id's here, so which one do I pick? AFAIK, I can't send to more than one address in one transaction?

balance_id is indeed like a UTXO .. but in bitshares you don't have change-addresses .. so what you do is basically just substract the amount from the balance and leave the rest in the balance_id/address.

in your case the "output" is bigger as your balance_id so that your tx has to combine several "inputs"/utxo

the "output" of the transaction is called "deposit_op_type" and contains a "withdraw_condition" .. which is usually "withdraw_signature_type" .. so you can withdraw with a valid signature ..

as for the "claim_input_data" .. my guess is that this field is required for some specialized withdraw conditions such as the withdraw_by_password .. and contains a parameter of some kind

Offline monsterer

every withdraw tx uses a balance_id (address) that holds funds to withdraw from ..
you can just send the funds there and the client should catch up that transaction ..
there's no need to 'identify' the unregistered account .. just refund to the address (balance_id) you received the money from ..

Are there any docs on what all these fields mean? I had assumed balance_id was like a UTXO and that 'from_account' was the sender.

Take a look at part of this deposit:

Code: [Select]
{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTS6UCvWSmZAsSmhp5E4JRrTLqirBFu7Lfng",
            "amount": 10000,
            "claim_input_data": ""
          }
        },{
          "type": "withdraw_op_type",
          "data": {
            "balance_id": "BTSASw7dDN1u3VaSNw5SNYk1WNN9uKBWZoDU",
            "amount": 10000,
            "claim_input_data": ""
          }
        }

As you can see there are two balance_id's here, so which one do I pick? AFAIK, I can't send to more than one address in one transaction?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
every withdraw tx uses a balance_id (address) that holds funds to withdraw from ..
you can just send the funds there and the client should catch up that transaction ..
there's no need to 'identify' the unregistered account .. just refund to the address (balance_id) you received the money from ..

Offline monsterer

I can refund a transaction from a registered account by looking at the from_account field, which is their account name. An unregistered account has a stealth public key in place of the account name - so, how do I know where to send the refund?
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads