I create an asset with Alice as owner and then i make a transaction to Bobr but BigchainDB lets me make another transaction from Alice to Peter.
Ubuntu 16.04
BigchainDB 2.0.0b6
CODE: (JavaScript)
const driver = require('bigchaindb-driver')
const API_PATH = 'http://localhost:9984/api/v1/'
const conn = new driver.Connection(API_PATH)
const alice = new driver.Ed25519Keypair()
const bob = new driver.Ed25519Keypair()
const peter = new driver.Ed25519Keypair()
console.log('Alice: ', alice.publicKey)
console.log('Bob: ', bob.publicKey)
console.log('Peter: ', peter.publicKey)
const assetdata = {
'bicycle': {
'serial_number': 'abcd1234',
'manufacturer': 'Bicycle Inc.',
}
}
const metadata = {'planet': 'earth'}
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
metadata,
// A transaction needs an output
[ driver.Transaction.makeOutput(
driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
const txCreateAliceSimpleSigned = driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
conn.postTransactionCommit(txCreateAliceSimpleSigned)
.then(retrievedTx => {
console.log('Transaction', retrievedTx.id, 'successfully posted.')
})
.then(() => {
const txTransferBob = driver.Transaction.makeTransferTransaction(
// signedTx to transfer and output index
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
// metadata
{price: '100 euro'}
)
let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey);
return conn.postTransactionCommit(txTransferBobSigned)
})
.then(tx => {
console.log('Response from BDB server:', tx)
console.log('Is Bob the owner?', tx['outputs'][0]['public_keys'][0] == bob.publicKey)
console.log('Was Alice the previous owner?', tx['inputs'][0]['owners_before'][0] == alice.publicKey )
})
.then(() => {
console.log("Another transaction from Alice, but now she is not the owner")
const txTransferPeter = driver.Transaction.makeTransferTransaction(
// signedTx to transfer and output index
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(peter.publicKey))],
// metadata
{price: '200 euro'}
)
let txTransferPeterSigned = driver.Transaction.signTransaction(txTransferPeter, alice.privateKey);
return conn.postTransactionCommit(txTransferPeterSigned)
})
.then(tx => {
console.log('Response from BDB server:', tx)
console.log('Is Bob the owner?', tx['outputs'][0]['public_keys'][0] == bob.publicKey)
console.log('Is Peter the owner?', tx['outputs'][0]['public_keys'][0] == peter.publicKey)
console.log('Was Alice the previous owner?', tx['inputs'][0]['owners_before'][0] == alice.publicKey )
})
.then(() => {
console.log("FININSH")
})
TERMINAL:
Alice: GYmQqKp561uRyQqH54whLwbVCS9PzN8R6372AZZqXVqi
Bob: j9bUqPELQQCrpjeVhodZLrDHdf4R8XrvrMdEHC9Zxfc
Peter: 6UPWcgQKhGgbmZvmnz7CNgA7Qd9tofWBSp3kMFt9z8Pu
Transaction 322ba8f35688cb2142314f3cb4701784455bdfd0a90cba916ac597106755d551 successfully posted.
Response from BDB server: { asset:
{ id:
'322ba8f35688cb2142314f3cb4701784455bdfd0a90cba916ac597106755d551' },
id:
'90093f67e630f582c2c0dd8eaba6550c1d949f84bb6fe2aed2167a4c2a0fb6af',
inputs:
[ { fulfillment:
'pGSAIOcChkmXLDlyYDH3cxTRtsZeTEpjIk3Nw9OowQ_dYeYpgUBlkDe-16g7mM47TaNR5DP3p3FFg3F5TQKvlDhpRHd6PYl5-nc88SZumNupCn6niJgujyjP4WFX_ebmO2eSsDEC',
fulfills: [Object],
owners_before: [Array] } ],
metadata: { price: '100 euro' },
operation: 'TRANSFER',
outputs:
[ { amount: '1', condition: [Object], public_keys: [Array] } ],
version: '2.0' }
Is Bob the owner? true
Was Alice the previous owner? true
Another transaction from Alice, but now she is not the owner
Response from BDB server: { asset:
{ id:
'322ba8f35688cb2142314f3cb4701784455bdfd0a90cba916ac597106755d551' },
id:
'b78d0d26d39477e6ed9a44f8d97b999f3f2a2e7303aea6fdfb6c154a52f2f65b',
inputs:
[ { fulfillment:
'pGSAIOcChkmXLDlyYDH3cxTRtsZeTEpjIk3Nw9OowQ_dYeYpgUDmPm5CYHwSryHHBGENUpY1bnN5DzpJ0tlhsS5lCfu2Fk2vACYLe4Co_Nzo6JsetQTXos29ye_zqhwkGE7XIaEC',
fulfills: [Object],
owners_before: [Array] } ],
metadata: { price: '200 euro' },
operation: 'TRANSFER',
outputs:
[ { amount: '1', condition: [Object], public_keys: [Array] } ],
version: '2.0' }
Is Bob the owner? false
Is Peter the owner? true
Was Alice the previous owner? true
FININSH
I create an asset with Alice as owner and then i make a transaction to Bobr but BigchainDB lets me make another transaction from Alice to Peter.
Ubuntu 16.04
BigchainDB 2.0.0b6
CODE: (JavaScript)
TERMINAL:
Alice: GYmQqKp561uRyQqH54whLwbVCS9PzN8R6372AZZqXVqi Bob: j9bUqPELQQCrpjeVhodZLrDHdf4R8XrvrMdEHC9Zxfc Peter: 6UPWcgQKhGgbmZvmnz7CNgA7Qd9tofWBSp3kMFt9z8Pu Transaction 322ba8f35688cb2142314f3cb4701784455bdfd0a90cba916ac597106755d551 successfully posted. Response from BDB server: { asset: { id: '322ba8f35688cb2142314f3cb4701784455bdfd0a90cba916ac597106755d551' }, id: '90093f67e630f582c2c0dd8eaba6550c1d949f84bb6fe2aed2167a4c2a0fb6af', inputs: [ { fulfillment: 'pGSAIOcChkmXLDlyYDH3cxTRtsZeTEpjIk3Nw9OowQ_dYeYpgUBlkDe-16g7mM47TaNR5DP3p3FFg3F5TQKvlDhpRHd6PYl5-nc88SZumNupCn6niJgujyjP4WFX_ebmO2eSsDEC', fulfills: [Object], owners_before: [Array] } ], metadata: { price: '100 euro' }, operation: 'TRANSFER', outputs: [ { amount: '1', condition: [Object], public_keys: [Array] } ], version: '2.0' } Is Bob the owner? true Was Alice the previous owner? true Another transaction from Alice, but now she is not the owner Response from BDB server: { asset: { id: '322ba8f35688cb2142314f3cb4701784455bdfd0a90cba916ac597106755d551' }, id: 'b78d0d26d39477e6ed9a44f8d97b999f3f2a2e7303aea6fdfb6c154a52f2f65b', inputs: [ { fulfillment: 'pGSAIOcChkmXLDlyYDH3cxTRtsZeTEpjIk3Nw9OowQ_dYeYpgUDmPm5CYHwSryHHBGENUpY1bnN5DzpJ0tlhsS5lCfu2Fk2vACYLe4Co_Nzo6JsetQTXos29ye_zqhwkGE7XIaEC', fulfills: [Object], owners_before: [Array] } ], metadata: { price: '200 euro' }, operation: 'TRANSFER', outputs: [ { amount: '1', condition: [Object], public_keys: [Array] } ], version: '2.0' } Is Bob the owner? false Is Peter the owner? true Was Alice the previous owner? true FININSH