diff --git a/_src/_assets/styles/bigchain/_syntax.scss b/_src/_assets/styles/bigchain/_syntax.scss index e366aae..7893905 100644 --- a/_src/_assets/styles/bigchain/_syntax.scss +++ b/_src/_assets/styles/bigchain/_syntax.scss @@ -29,7 +29,7 @@ } .highlight .l { - color: #ccc; + color: $code-color; } .highlight .n { @@ -41,7 +41,7 @@ } .highlight .x { - color: #ccc; + color: $code-color; } .highlight .p { @@ -70,7 +70,7 @@ } .highlight .ge { - color: #ccc; + color: $code-color; font-style: italic; } @@ -97,7 +97,7 @@ } .highlight .gs { - color: #ccc; + color: $code-color; font-weight: bold; } @@ -160,11 +160,11 @@ } .highlight .no { - color: #ccc; + color: $code-color; } .highlight .nd { - color: #ccc; + color: $code-color; } .highlight .ni { @@ -181,7 +181,7 @@ } .highlight .nl { - color: #ccc; + color: $code-color; } .highlight .nn { @@ -189,11 +189,11 @@ } .highlight .nx { - color: #ccc; + color: $code-color; } .highlight .py { - color: #ccc; + color: $code-color; } .highlight .nt { @@ -209,7 +209,7 @@ } .highlight .w { - color: #ccc; + color: $code-color; } .highlight .mf { diff --git a/_src/_assets/styles/bigchain/_variables.scss b/_src/_assets/styles/bigchain/_variables.scss index 7d1f745..863328f 100644 --- a/_src/_assets/styles/bigchain/_variables.scss +++ b/_src/_assets/styles/bigchain/_variables.scss @@ -121,7 +121,7 @@ $kbd-bg: $code-bg !default; $pre-bg: $code-bg !default; $pre-color: $code-color !default; -$pre-scrollable-max-height: 340px !default; +$pre-scrollable-max-height: 28rem !default; // diff --git a/_src/_guides/tutorial-car-telemetry-app.md b/_src/_guides/tutorial-car-telemetry-app.md index 656a195..6f0273d 100644 --- a/_src/_guides/tutorial-car-telemetry-app.md +++ b/_src/_guides/tutorial-car-telemetry-app.md @@ -47,7 +47,6 @@ const vehicle ={ power: { engine: '2.5', cv: '220 cv', - } consumption: '10.8 l', } @@ -57,7 +56,6 @@ To post a transaction in BDB, firs we need to create it, then sign it and then s ```js function createCar() { - // Construct a transaction payload const txCreate = BigchainDB.Transaction.makeCreateTransaction( { @@ -67,7 +65,7 @@ function createCar() { datetime: new Date().toString() }, // Metadata contains information about the transaction itself -// (can be `null` if not needed) + // (can be `null` if not needed) { mileage: 0 }, @@ -90,7 +88,7 @@ function createCar() { `carOwner.publicKey` can be considered as the Input for the transaction. When you sign a transaction in BigchainDB you have the rights for the next TRANSFER transactions that could be done with this asset. You always sign with a private key that is derivative from the seed phrase. -With the pollStatusAndFetchTransaction we check the status of the transaction every 0.5 seconds. +With the `pollStatusAndFetchTransaction` we check the status of the transaction every 0.5 seconds. Once a transaction ends up in a decided-valid block, that's it. There's no changing it, no deleting it. But you can use `TRANSFER` transactions (with their arbitrary metadata) to store whatever you like, including information that could be interpreted as changing an asset (if that's how you want it to be interpreted). @@ -100,23 +98,22 @@ Before creating the transfer transaction, we search for the last transaction wit ```js conn.listTransactions(assetId) -.then((txList) => { - if (txList.length <= 1) { - return txList - } - const inputTransactions = [] - txList.forEach((tx) => - tx.inputs.forEach(input => { - // Create transactions have null fulfills by definition - if (input.fulfills) { - inputTransactions.push(input.fulfills.transaction_id) - } - }) - ) - // In our case there should be just one input that has not beeen spent with the asseId - return unspents = txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1) - -}) + .then((txList) => { + if (txList.length <= 1) { + return txList + } + const inputTransactions = [] + txList.forEach((tx) => + tx.inputs.forEach(input => { + // Create transactions have null fulfills by definition + if (input.fulfills) { + inputTransactions.push(input.fulfills.transaction_id) + } + }) + ) + // In our case there should be just one input that has not beeen spent with the asseId + return unspents = txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1) + }) ``` The `listTransactions` method of BigchainDB retrieves all of the create and transfer transaction with the asset id. Then we check for the inputs that have not been spent. In this tutorial we are just working with one input and one ouput for each transaction, so there should be just one input that has not been spent yet, the one belonging to the last transaction. @@ -124,52 +121,49 @@ The `listTransactions` method of BigchainDB retrieves all of the create and tran We now create the transfer transaction: ```js -function updateMileage(assetId, mileageValue){ +function updateMileage(assetId, mileageValue) { // Update the car with a new mileage of 55km. First we query for the asset car that we created - conn.listTransactions(assetId) - .then((txList) => { - if (txList.length <= 1) { - return txList - } - const inputTransactions = [] - txList.forEach((tx) => - tx.inputs.forEach(input => { - if (input.fulfills) { - inputTransactions.push(input.fulfills.transaction_id) - } - }) - ) - // In our case there should be just one input not spend with the asseId - return unspents = txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1) + .then((txList) => { + if (txList.length <= 1) { + return txList + } + const inputTransactions = [] + txList.forEach((tx) => + tx.inputs.forEach(input => { + if (input.fulfills) { + inputTransactions.push(input.fulfills.transaction_id) + } + }) + ) + // In our case there should be just one input not spend with the asseId + return unspents = txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1) + }) - }) - - .then((tx) => { - conn.getTransaction(tx[0].id) - .then((txCreated) => { - console.log('Found', txCreated) - const createTranfer = BigchainDB.Transaction.makeTransferTransaction( - txCreated, - { - mileage: txCreated.metadata.mileage + mileageValue, - units: 'km' - }, [BigchainDB.Transaction.makeOutput( - BigchainDB.Transaction.makeEd25519Condition(carOwner.publicKey))], - 0 - ) - - // Sign with the owner of the car as she was the creator of the car - const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer, carOwner.privateKey) - console.log('signed Transfer trans', signedTransfer) - conn.postTransaction(signedTransfer) - .then(() => conn.pollStatusAndFetchTransaction(signedTransfer.id)) - .then(res => { - console.log('Transfer Transaction ', signedTransfer.id, 'accepted','with ',mileageValue, 'km',) - }) - }) - }) + .then((tx) => { + conn.getTransaction(tx[0].id) + .then((txCreated) => { + console.log('Found', txCreated) + const createTranfer = BigchainDB.Transaction.makeTransferTransaction( + txCreated, + { + mileage: txCreated.metadata.mileage + mileageValue, + units: 'km' + }, [BigchainDB.Transaction.makeOutput( + BigchainDB.Transaction.makeEd25519Condition(carOwner.publicKey))], + 0 + ) + // Sign with the owner of the car as she was the creator of the car + const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer, carOwner.privateKey) + console.log('signed Transfer trans', signedTransfer) + conn.postTransaction(signedTransfer) + .then(() => conn.pollStatusAndFetchTransaction(signedTransfer.id)) + .then(res => { + console.log('Transfer Transaction ', signedTransfer.id, 'accepted','with ',mileageValue, 'km',) + }) + }) + }) } ```