Skip to content

Commit

Permalink
Merge pull request #218 from innoprenuer/master
Browse files Browse the repository at this point in the history
updated examples with latest api functions
  • Loading branch information
innopreneur committed Jul 6, 2018
2 parents 9dfd7e2 + fadc1bd commit 96fd99e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
8 changes: 4 additions & 4 deletions examples/src/basic-usage-async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand All @@ -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 ======== //
Expand Down
16 changes: 6 additions & 10 deletions examples/src/basic-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,23 @@ 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' }
)

// 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
Expand Down
4 changes: 2 additions & 2 deletions examples/src/query-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}


Expand Down

0 comments on commit 96fd99e

Please sign in to comment.