1
0
mirror of https://github.com/bigchaindb/site.git synced 2025-02-14 21:10:28 +01:00

flatten promises

This commit is contained in:
manolodewiner 2017-11-24 12:49:23 +01:00
parent 20dec18594
commit 26d651a52c

View File

@ -153,26 +153,28 @@ function updateMileage(assetId, mileageValue) {
return txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1) return txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1)
}) })
.then((tx) => { .then((tx) => {
conn.getTransaction(tx[0].id) // As there is just one input
.then((txCreated) => { return conn.getTransaction(tx[0].id)
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 .then((txCreated) => {
const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer, carOwner.privateKey) const createTranfer = BigchainDB.Transaction.makeTransferTransaction(
return conn.postTransaction(signedTransfer) txCreated, {
}) mileage: txCreated.metadata.mileage + mileageValue,
.then((signedTransfer) => conn.pollStatusAndFetchTransaction(signedTransfer.id)) units: 'km'
.then(res => { }, [BigchainDB.Transaction.makeOutput(
document.body.innerHTML += '<h3>Transfer Transaction created</h3>'; BigchainDB.Transaction.makeEd25519Condition(carOwner.publicKey))],
document.body.innerHTML += res.id 0
}) )
// Sign with the owner of the car as she was the creator of the car
const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer, carOwner.privateKey)
return conn.postTransaction(signedTransfer)
})
.then((signedTransfer) => conn.pollStatusAndFetchTransaction(signedTransfer.id))
.then(res => {
document.body.innerHTML += '<h3>Transfer Transaction created</h3>';
document.body.innerHTML += res.id
}) })
} }
``` ```