-
Notifications
You must be signed in to change notification settings - Fork 439
API Functions for Exchange Implementation #576
Comments
Sorry it took so long to get here, but I'm working on the wallet right now. The new wallet should be coded up by Aug. 1st, and the first release with the changes should be on Aug. 15th. Wanted to run the api calls by you though.
I wasn't planning on having this call list all transactions related to the wallet, it seemed unwieldy.
From the transaction you will be able to parse the amount, the confirmations, the source(s), the destination, the ids (both of the outputs and of the transaction), and the timestamp, as well as the actual raw transaction.
There will be a few other calls related to backups, setting passwords, and similar functions, but the above are the ones related to sending and receiving coins. |
If /wallet/siacoins/send automatically selects inputs from all addresses in the wallet (rather than requiring a single source address to be specified), then an exchange will need a method to list all transactions in the wallet. If you provide only the methods proposed above, I would need to construct this list using /wallet/$(ADDR) by querying every deposit address, collecting the txns, and (if /wallet/$(ADDR) provides only txns and no further transaction information) fetching the amount, destination, and confirmations of each transaction. As more deposit addresses are generated, this could end up becoming very slow; it is preferable to minimize the number of API queries needed. Unless sending funds must be done by specifying both a source and a destination address, knowing the balances of each address in the wallet is actually of little use to an exchange; because trades happen off the blockchain, the balance of a user's deposit address rarely matches that user's balance on the exchange or even the sum of that user's deposits. |
I am concerned about the size of a I guess we could add pagination, so that if the size exceeds 1mb or something, it'd be broken up into several pages, and you could specify a page with each call. I think that's reasonable. |
Most wallet APIs provide a way to limit the number of transactions returned. Bitcoin's allows you to specify such a number, and will return the latest n transactions. Others allow you to specify a starting block, sometimes an ending block as well. The latter is ideal -- specifying a starting block would return all transactions between that block and the latest or a specified ending block. |
Working on it now, I think I can have everything you've request ready in the next release. Timestamps on the transactions are vague. Do you want the time that the transaction was first seen, or the timestamp on the block it appeared in? Transactions in Sia don't have a timestamp on their own. First block appearance would be pretty easy, but timestamp first seen would be harder. |
First block appearance is fine. |
For the most part, the implementation is complete. I still need to update the actually http api, but the backend is ready. All wallet keys and seeds are encrypted on disk. After loading, the wallet needs to be unlocked. The wallet won't start until it has been unlocked. The wallet is unlocked using a password/key. The wallet can be relocked by calling 'Close', which will wipe all of the keys from memory (to the extent possible. Because of context switching, swap space, and other confounding variables, it's possible that keys will be in memory unreachable to siad) You can call unlock and close as many times as you like. When requesting transaction history, you can either ask for all transactions, or you can ask for transactions between two block heights [start, end]. Instead of actual transactions being returned, a 'Wallet Transaction' will be returned, which contains a single siacoin or siafund input or output. It also contains the full transaction (which means there's high redundancy for large transactions - this could perhaps be replaced by using transaction ids). As an example, transaction A might have 3 inputs, 1 output, and 1 refund. 5 wallet transactions will be created. One for each input, and one for each output. Each will specify the type of movement (input vs. output, and siacoin vs. siafund), the address involved (generally only useful for incoming coins (appearing as outputs in a transaction), as the wallet arbitrarily selects addresses when creating inputs to a transaction), and the value. Each wallet transaction contains a timestamp and a confirmation height (to get the number of confirmations, you'll need to compare to the current height). All 5 are guaranteed to appear consecutively in the transaction history. When requesting a balance, you can request 'ConfirmedBalance' and 'UnconfirmedBalance'. Confirmed balance currently will only look at 1 confirmation, other than parsing the transaction history yourself you can't get 6 confirmation balance right now. Unconfirmed balance will return the number of incoming and outgoing siacoins, which will include refunds. For example, if you create an unconfirmed transaction that sends 5 coins, and a 500 coin input is used, the result reported will be 500 outgoing ,and 495 incoming. Hope this is all okay. Let me know if there are changes you think should be made. |
Queries:
/wallet [GET]Function: Returns basic information about the wallet, such as whether the Parameters: none Response:
'encrypted' indicates whether the wallet has been encrypted or not. If the 'unlocked' indicates whether the wallet is currently locked or unlocked. Some /wallet/close [PUT]Function: Locks and closes the wallet, preparing for shutdown. After being Parameters: none Response: Standard. /wallet/history [GET]Function: Return a list of transactions related to the wallet. Parameters:
Response:
'transactions' is a list of 'WalletTransactions'. Wallet transactions are A wallet transaction takes the
'TransactionID' is the id of the transaction from which the wallet transaction 'ConfirmationHeight' is the height at which the transaction was confirmed. The 'ConfirmationTimestamp' is the time at which a transaction was confirmed. The 'FundType' indicates what type of fund is represented by the wallet 'OutputID' is the id of the output. OutputIDs will always be unique. 'RelatedAddress' is the address that is affected. For inputs (outgoing money), 'Value' indicates how much money has been moved in the input or output. /wallet/history/$(addr) [GET]Function: Return all of the transaction related to a specific address. Parameters: none Response:
'transactions' is a list of 'WalletTransactions' that affect the input address. /wallet/seed [GET]Function: Return the seed that is being used to generate addresses. This seed Parameters:
'dictionary' is the name of the dicitionary that should be used when encoding Response:
'primarySeed' is the seed that is actively being used to generate new addresses 'addressesRemaining' is the number of addresses that remain in the primary seed 'backupSeeds' is a list of seeds that are no longer used to generate new A seed is an encoded version of a 128 bit random seed. The output is 15 words /wallet/seed [PUT]Function: Get a new address from the wallet generated by the primary seed. An Parameters: none Response:
'address' is the address that cna /wallet/seed [POST]Function: Fetch a new seed for the wallet. The old seed will be added to the Parameters:
'verification' must be set to true, or an error is returned. This is to prevent 'dictionary' is the name of the dictionary that should be used when encoding Response:
'newSeed' is the new seed that will be used as the seed for generating new /wallet/siacoins [GET]Function: get the siacoin balance (confirmed and unconfirmed) of the wallet. Parameters: none Response:
'confirmedSiacoinBalance' is the number of siacoins available to the wallet as 'unconfirmedOutgoingSiacoins' is the number of siacoins that are leaving the 'unconfirmedIncomingSiacoins' is the number of siacoins are entering the wallet /wallet/siacoins [PUT]Function: Send siacoins to an address. The outputs are arbitrarily selected Parameters:
'amount' is the number of siacoins being sent. 'destination' is the address that is receiving the coins. Response: standard /wallet/siafunds [GET]Function: get the siafund balance of the wallet. Only the confirmed balance is Parameters: none Response:
'siafundBalance' is the number of siafunds available to the wallet as 'siacoinClaimBalance' is the number of siacoins that can be claimed from the /wallet/siafunds [PUT]Function: Send siafunds to an address. The outputs are arbitrarily selected Parameters:
'amount' is the number of siafunds being sent. 'destination' is the address that is receiving the funds. Response: standard /wallet/transaction/$(id) [GET]Function: Get the transaction associated with a specific transaction id. Parameters: none Response:
'transaction' is a 'types.Transaction'. The full transaction can be seen in /wallet/unlock [PUT]Function: Unlock the wallet. The wallet is capable of knowing whether the Parameters:
Response: standard |
@poloniex @agundy @Mingling94 @lukechampine the above comment contains the rough draft of the specification for the wallet api. If there is anything that is unusual, unusable, or you think could be improved, please let me know. @poloniex, let me know if this adds all of the features that you will need to add Sia to an exchange. The majority of this has been implemented already. |
The wallet transaction thing is a little cumbersome for exchange purposes. The API described is sufficient for an exchange implementation, but I will have to construct the list of transactions I described myself -- either by adding up all the wallet transactions, or fetching transactions individually by id (probably the former). |
I think the API could be less repetitious and more logically consistent by combining /wallet/transaction [POST]
while also combining /wallet/balance [GET]
|
People should not make their own passwords. People make grossly insecure passwords, and dictionary attacks are extremely powerful. While they could make their own password when locking the wallet, the vast majority of people make passwords (even at 24+ characters!) that can be guessed in a relatively short amount of time using a dictionary attack. That's why we recommend you use the seed password - it's got a full 128 bits of entropy and is immune to dictionary attacks. I could put all of the balance stuff into the /wallet [GET] call. I'm not sure that it makes sense to combine the /siacoins and /siafunds calls when sending money. |
|
The new api functions have been implemented and merged into master. Documentation on the calls can be found in doc/API.md. Further discussion/requests can be continued by opening a new issue. |
Some additional features are needed for exchange implementation to be possible:
The text was updated successfully, but these errors were encountered: