fibercrypto / fibercrypto/skyxcommons
[api] Many-inputs tx
- Dominant language
- No language data
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
[POST] /api/transactions/many-inputs
Should build not signed transaction with many inputs.
If the transaction with the specified `operationId` has already been built by one of the `[POST] /api/transactions/*` call, it should be ignored and regular response (as in the first request) should be returned.
Request
```js
{
// Operation ID
“operationId”: “guid”,
// Sources
“inputs”: [
{
// Source address
“fromAddress”: “string”,
// Amount to transfer from the fromAddress .
// Integer as string, aligned
// to the droplet precision exponent. Actual value can be
// calculated as
// x = amount / (10 ^ asset.Accuracy)
“amount”: “string”
}
],
// Destination address
“toAddress”: “string”,
// ticker ID of the fiber coin , SKY by default
“assetId”: “string”
}
```
Response
```js
{
// Error code.
// Can be empty.
// Should be non empty if an error that match one of the
// listed code is occured. For other errors use HTTP
// status codes.
// enum values:
// - amountIsTooSmall : amount is too small to execute
// transaction
// - notEnoughBalance : transaction can’t be executed due
// to balance insufficiency on the source address.
"errorCode": "enum",
// The transaction context which will be passed to the
// [POST] /api/sign
// Should be not empty when result is successful.
“transactionContext”: “string”
}
```
Python implementation
```py
@api.route('/api/transactions/many-inputs', methods=['POST'])
def transactions_many_inputs():
if not request.json:
return make_response(jsonify(build_error("Input format error")), 400)
params = {'operationID', 'inputs', 'toAddress', 'assetId'}
if all(x not in params for x in request.json):
return make_response(jsonify(build_error("Input data error")), 400)
result = transaction_many_inputs(request.json)
if "transactionContext" in result:
return jsonify(result)
return jsonify({"status": 500, "error": "Invalid response"})
```
```py
def transaction_many_inputs(values):
"""
build a transaction with many inputs
"""
csrf = requests.get(form_url(base_url, "/csrf")).json()
if not csrf or "csrf_token" not in csrf:
return {"status": 500, "error": "Unknown server error"}
resp = requests.post(
form_url(base_url, "/transactions/many-inputs"),
data=values,
headers={'X-CSRF-Token': csrf['csrf_token']}
)
if not resp:
return {"status": 500, "error": "Unknown server error"}
if resp.status_code != 200:
return {"status": 500, "error": "Unknown server error"}
return resp.json()
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.