Example #1
0
 new Promise((resolve, reject) => {
     const txLocal = localStorage.getItem(txId)
     if (txLocal) {
         resolve(JSON.parse(txLocal))
     } else {
         let txFetched
         let blockFetched
         conn.getTransaction(txId)
             .then(tx => {
                 txFetched = tx
                 return conn.listBlocks(txId)
             })
             .then(block => {
                 blockFetched = block
                 return conn.listVotes(block[0])
             })
             .then(votes => {
                 txFetched = {
                     ...txFetched,
                     block: blockFetched,
                     votes
                 }
                 localStorage.setItem(txId, JSON.stringify(txFetched))
                 resolve(txFetched)
             })
             .catch(reason => reject(reason))
     }
 })
Example #2
0
export const publish = (publicKey, privateKey, payload, metadata) => {
    // Create a transation
    const tx = driver.Transaction.makeCreateTransaction(
        payload,
        metadata,
        [
            driver.Transaction.makeOutput(
                driver.Transaction.makeEd25519Condition(publicKey))
        ],
        publicKey
    )
    // sign/fulfill the transaction
    const txSigned = driver.Transaction.signTransaction(tx, privateKey)

    // send it off to BigchainDB
    return conn.postTransaction(txSigned)
        .then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
        .then(() => txSigned)
}
Example #3
0
export const transfer = (tx, fromPublicKey, fromPrivateKey, toPublicKey, metadata) => {
    const txTransfer = driver.Transaction.makeTransferTransaction(
        tx,
        metadata,
        [
            driver.Transaction.makeOutput(
                driver.Transaction.makeEd25519Condition(toPublicKey)
            )
        ],
        0
    )

    const txTransferSigned = driver.Transaction.signTransaction(txTransfer, fromPrivateKey)
    // send it off to BigchainDB
    return conn.postTransaction(txTransferSigned)
        .then(() =>
            conn.pollStatusAndFetchTransaction(txTransferSigned.id))
        .then(() => txTransferSigned)
}
Example #4
0
export const listTransactions = (assetId) =>
    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)
                    }
                })
            )
            const unspents = txList.filter((tx) => inputTransactions.indexOf(tx.id) === -1)
            if (unspents.length) {
                let tipTransaction = unspents[0]
                let tipTransactionId = tipTransaction.inputs[0].fulfills.transaction_id
                const sortedTxList = []
                while (true) { // eslint-disable-line no-constant-condition
                    sortedTxList.push(tipTransaction)
                    try {
                        tipTransactionId = tipTransaction.inputs[0].fulfills.transaction_id
                    } catch (e) {
                        break
                    }
                    if (!tipTransactionId) {
                        break
                    }
                    tipTransaction = txList.filter((tx) => // eslint-disable-line no-loop-func
                        tx.id === tipTransactionId)[0]
                }
                return sortedTxList.reverse()
            } else {
                console.error('something went wrong while sorting transactions',
                    txList, inputTransactions)
            }
            return txList
        })
Example #5
0
 .then(block => {
     blockFetched = block
     return conn.listVotes(block[0])
 })
Example #6
0
 .then(tx => {
     txFetched = tx
     return conn.listBlocks(txId)
 })
Example #7
0
export const getUnspents = (publicKey, spent = undefined, callback) => // eslint-disable-line no-unused-vars
    conn.listOutputs(publicKey, spent)
        .then(unspents => unspents.map(elem => elem.transaction_id))
Example #8
0
 .then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
Example #9
0
export const searchAssets = (search) =>
    conn.searchAssets(search)
        .then(assetList => assetList.map(asset => asset.id))