1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +01:00

Merge pull request #197 from bigchaindb/adding_asyncMethod

adding async method
This commit is contained in:
Manolo 2018-06-28 17:30:55 +02:00 committed by GitHub
commit 5c977696ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 7 deletions

View File

@ -51,14 +51,17 @@ Older versions
anymore the `pollStatusAndFetchTransaction()` method as there are three anymore the `pollStatusAndFetchTransaction()` method as there are three
different ways of posting a transaction: different ways of posting a transaction:
- `async` using the `postTransaction`: the response will return immediately and not wait to see if the transaction is valid. - `commit` using the `postTransaction` or the `postTransactionCommit`: the response will return after the transaction is committed to a block.
- `sync` using the `postTransactionSync`: the response will return after the transaction is validated. - `sync` using the `postTransactionSync`: the response will return after the transaction is validated.
- `commit` using the `postTransactionCommit`: the response will return after the transaction is committed to a block. - `async` using the `postTransactionAsync`: the response will return immediately and not wait to see if the transaction is valid.
By default in the docs we will use the `postTransactionCommit` as is way of By default in the docs we will use the `postTransactionCommit` as is way of
being sure that the transaction is validated and commited to a block, so being sure that the transaction is validated and commited to a block, so
there will not be any issue if you try to do any other action with the asset immediately. there will not be any issue if you try to do any other action with the asset immediately.
Note: In order to not create breaking changes, both methods `postTransaction` and `postTransactionCommit` are kept although
they do exactly the same
**Version 3.2.x** **Version 3.2.x**

View File

@ -24,6 +24,7 @@ export default class Connection {
'outputs': 'outputs', 'outputs': 'outputs',
'transactions': 'transactions', 'transactions': 'transactions',
'transactionsSync': 'transactions?mode=sync', 'transactionsSync': 'transactions?mode=sync',
'transactionsAsync': 'transactions?mode=async',
'transactionsCommit': 'transactions?mode=commit', 'transactionsCommit': 'transactions?mode=commit',
'transactionsDetail': 'transactions/%(transactionId)s', 'transactionsDetail': 'transactions/%(transactionId)s',
'assets': 'assets', 'assets': 'assets',
@ -118,10 +119,7 @@ export default class Connection {
* @param transaction * @param transaction
*/ */
postTransaction(transaction) { postTransaction(transaction) {
return this._req(this.getApiUrls('transactions'), { return this.postTransactionCommit(transaction)
method: 'POST',
jsonBody: transaction
})
} }
/** /**
@ -134,6 +132,18 @@ export default class Connection {
}) })
} }
/**
* @param transaction
*/
postTransactionAsync(transaction) {
return this._req(this.getApiUrls('transactionsAsync'), {
method: 'POST',
jsonBody: transaction
})
}
/** /**
* @param transaction * @param transaction
*/ */

View File

@ -27,6 +27,9 @@ test('Generate API URLS', t => {
'blocksDetail': 'blocks/%(blockHeight)s', 'blocksDetail': 'blocks/%(blockHeight)s',
'outputs': 'outputs', 'outputs': 'outputs',
'transactions': 'transactions', 'transactions': 'transactions',
'transactionsSync': 'transactions?mode=sync',
'transactionsAsync': 'transactions?mode=async',
'transactionsCommit': 'transactions?mode=commit',
'transactionsDetail': 'transactions/%(transactionId)s', 'transactionsDetail': 'transactions/%(transactionId)s',
'assets': 'assets', 'assets': 'assets',
} }

View File

@ -35,7 +35,39 @@ test('Valid CREATE transaction', t => {
) )
const txSigned = Transaction.signTransaction(tx, alice.privateKey) const txSigned = Transaction.signTransaction(tx, alice.privateKey)
return conn.postTransactionCommit(txSigned) return conn.postTransaction(txSigned)
.then(resTx => t.truthy(resTx))
})
test('Valid CREATE transaction using async', t => {
const conn = new Connection(API_PATH)
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
return conn.postTransactionAsync(txSigned)
.then(resTx => t.truthy(resTx))
})
test('Valid CREATE transaction using sync', t => {
const conn = new Connection(API_PATH)
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
return conn.postTransactionSync(txSigned)
.then(resTx => t.truthy(resTx)) .then(resTx => t.truthy(resTx))
}) })