1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +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 ======== // // ======== Post Transaction and Fetch Result ======== //
await conn.postTransaction(txCreateAliceSimpleSigned) await conn.postTransactionCommit(txCreateAliceSimpleSigned)
await conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id) await conn.getTransaction(txCreateAliceSimpleSigned.id)
const txTransferBob = driver.Transaction.makeTransferTransaction( const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }], [{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
@ -54,8 +54,8 @@ async function basicUsage() {
const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey) const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
await conn.postTransaction(txTransferBobSigned) await conn.postTransactionCommit(txTransferBobSigned)
await conn.pollStatusAndFetchTransaction(txTransferBobSigned.id) await conn.getTransaction(txTransferBobSigned.id)
// ======== Querying Assets ======== // // ======== Querying Assets ======== //

View File

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