1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-27 23:27:50 +01:00

updated examples with latest api functions

This commit is contained in:
Manan Patel 2018-07-06 14:47:32 +02:00
parent 9dfd7e20bf
commit fadc1bd567
3 changed files with 12 additions and 16 deletions

View File

@ -43,8 +43,8 @@ async function basicUsage() {
// ======== Post Transaction and Fetch Result ======== //
await conn.postTransaction(txCreateAliceSimpleSigned)
await conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id)
await conn.postTransactionCommit(txCreateAliceSimpleSigned)
await conn.getTransaction(txCreateAliceSimpleSigned.id)
const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
@ -54,8 +54,8 @@ async function basicUsage() {
const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
await conn.postTransaction(txTransferBobSigned)
await conn.pollStatusAndFetchTransaction(txTransferBobSigned.id)
await conn.postTransactionCommit(txTransferBobSigned)
await conn.getTransaction(txTransferBobSigned.id)
// ======== Querying Assets ======== //

View File

@ -36,17 +36,13 @@ const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
const txCreateAliceSimpleSigned =
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
// ======== Post Transaction and Fetch Result ======== //
conn.postTransaction(txCreateAliceSimpleSigned)
// Check status of transaction every 0.5 seconds until fulfilled
.then(() => conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id))
conn.postTransactionCommit(txCreateAliceSimpleSigned)
.then(() => conn.getTransaction(txCreateAliceSimpleSigned.id))
// ======== Transfer Bicycle to Bob ======== //
.then(() => {
.then((fetchedTx) => {
const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[{ tx: fetchedTx, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
{ price: '100 euro' }
)
@ -54,9 +50,9 @@ conn.postTransaction(txCreateAliceSimpleSigned)
// Sign transfer transaction with Alice's private key
const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
return conn.postTransaction(txTransferBobSigned)
return conn.postTransactionCommit(txTransferBobSigned)
})
.then(res => conn.pollStatusAndFetchTransaction(res.id))
.then(res => conn.getTransaction(res.id))
.then(tx => {
console.log('Is Bob the owner?', tx.outputs[0].public_keys[0] === bob.publicKey) // eslint-disable-line no-console
console.log('Was Alice the previous owner?', tx.inputs[0].owners_before[0] === alice.publicKey) // eslint-disable-line no-console

View File

@ -34,8 +34,8 @@ function createTx(assetdata) {
)
const txCreateSigned = driver.Transaction.signTransaction(txCreate, alice.privateKey)
return conn.postTransaction(txCreateSigned)
.then(() => conn.pollStatusAndFetchTransaction(txCreateSigned.id))
return conn.postTransactionCommit(txCreateSigned)
.then(() => conn.getTransaction(txCreateSigned.id))
}