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

docs updated to new makeTransferTransaction format

This commit is contained in:
manolodewiner 2017-11-01 17:45:27 +01:00 committed by tim
parent 9f385c440d
commit 6031868245
2 changed files with 72 additions and 73 deletions

View File

@ -47,10 +47,9 @@ This can be the mother Alice, or Carly herself.
output.public_keys = [carly.publicKey] output.public_keys = [carly.publicKey]
let transaction = driver.Transaction.makeTransferTransaction( let transaction = driver.Transaction.makeTransferTransaction(
txCreateAliceSimpleSigned, [{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
{'meta': 'Transfer to new user with conditions'},
[output], [output],
0 {'meta': 'Transfer to new user with conditions'}
); );
// Add alice as previous owner // Add alice as previous owner

View File

@ -173,22 +173,21 @@ First, let's prepare the transaction to be transferred.
.. code-block:: js .. code-block:: js
const txTransferBob = driver.Transaction.makeTransferTransaction( const txTransferBob = driver.Transaction.makeTransferTransaction(
// signedTx to transfer // signedTx to transfer and output index
txCreateAliceSimpleSigned, [{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
// metadata
{price: '100 euro'},
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))], [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
0
// metadata
{price: '100 euro'}
); );
The function ``makeTransferTransaction()`` needs following parameters: The function ``makeTransferTransaction()`` needs following parameters:
- Unspent transaction: Previous transaction you have control over (i.e. can fulfill its Output Condition) - Unspent outputs: Array of `unspent transactions outputs`. Each item contains `Transaction` itself and index of `unspent output` for that `Transaction`.
- Metadata for transaction (e.g. price of sold bike)
- Array of output objects to add to the transaction: Think of these as the recipients of the asset after the transaction. For `TRANSFER` transactions, this should usually just be a list of outputs wrapping Ed25519 conditions generated from the public keys of the recipients. - Array of output objects to add to the transaction: Think of these as the recipients of the asset after the transaction. For `TRANSFER` transactions, this should usually just be a list of outputs wrapping Ed25519 conditions generated from the public keys of the recipients.
- Indices of the outputs in `unspent transaction` that this transaction fulfills. - Metadata for transaction (e.g. price of sold bike)
Fulfill transaction by signing it with Alice's private key. Fulfill transaction by signing it with Alice's private key.
@ -331,12 +330,12 @@ Recap: Asset Creation & Transfer
// Transfer bicycle to Bob // Transfer bicycle to Bob
.then(() => { .then(() => {
const txTransferBob = driver.Transaction.makeTransferTransaction( const txTransferBob = driver.Transaction.makeTransferTransaction(
// signedTx to transfer // signedTx to transfer and output index
txCreateAliceSimpleSigned, [{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
// metadata
{price: '100 euro'},
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))], [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
0) // metadata
{price: '100 euro'}
)
// Sign with alice's private key // Sign with alice's private key
let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey) let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
@ -571,10 +570,10 @@ and further we transfer it from Bob to Chris. Expectations:
// Transfer bicycle from Alice to Bob // Transfer bicycle from Alice to Bob
.then(() => { .then(() => {
const txTransferBob = driver.Transaction.makeTransferTransaction( const txTransferBob = driver.Transaction.makeTransferTransaction(
txCreateAliceSimpleSigned, [{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
{'newOwner': 'Bob'},
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))], [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
0) {'newOwner': 'Bob'}
)
// Sign with alice's private key // Sign with alice's private key
txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey) txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
@ -588,10 +587,10 @@ and further we transfer it from Bob to Chris. Expectations:
// Second transfer of bicycle from Bob to Chris // Second transfer of bicycle from Bob to Chris
.then(tx => { .then(tx => {
const txTransferChris = driver.Transaction.makeTransferTransaction( const txTransferChris = driver.Transaction.makeTransferTransaction(
txTransferBobSigned, [{ tx: txTransferBobSigned, output_index: 0 }],
{'newOwner': 'Chris'},
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(chris.publicKey))], [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(chris.publicKey))],
0) {'newOwner': 'Chris'}
)
// Sign with bob's private key // Sign with bob's private key
let txTransferChrisSigned = driver.Transaction.signTransaction(txTransferChris, bob.privateKey) let txTransferChrisSigned = driver.Transaction.signTransaction(txTransferChris, bob.privateKey)
@ -676,15 +675,16 @@ This gives us 4 tokens to transfer.
.. code-block:: js .. code-block:: js
const txTransferDivisible = driver.Transaction.makeTransferTransaction( const txTransferDivisible = driver.Transaction.makeTransferTransaction(
txCreateAliceDivisibleSigned, [{ tx: txCreateAliceDivisibleSigned, output_index: 0 }],
{
metaDataMessage: 'I am specific to this transfer transaction'
},
[ [
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(carly.publicKey), '2'), driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(carly.publicKey), '2'),
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey), '1'), driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey), '1'),
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '1') driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '1')
], 0); ],
{
metaDataMessage: 'I am specific to this transfer transaction'
}
);
To make the use of the last parameter of ``makeTransferTransaction()`` function more clear, we will do another transfer. To make the use of the last parameter of ``makeTransferTransaction()`` function more clear, we will do another transfer.
We will fulfill the first and second output of the create transaction (0, 1) because Carly and Bob decide to redistribute some money. We will fulfill the first and second output of the create transaction (0, 1) because Carly and Bob decide to redistribute some money.
@ -695,16 +695,16 @@ We will fulfill the first and second output of the create transaction (0, 1) bec
This gives us 3 tokens to redistribute. I want to give 1 token to Carly and 2 tokens Alice. This gives us 3 tokens to redistribute. I want to give 1 token to Carly and 2 tokens Alice.
.. code-block:: js .. code-block:: js
const txTransferDivisibleInputs = driver.Transaction.makeTransferTransaction( const txTransferDivisibleInputs = driver.Transaction.makeTransferTransaction(
txTransferDivisibleSigned, [{ tx: txTransferDivisibleSigned, output_index: 0 }, { tx: txTransferDivisibleSigned, output_index: 1 }],
{
metaDataMessage: 'I am specific to this transfer transaction'
},
[ [
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(carly.publicKey), '1'), driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(carly.publicKey), '1'),
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '2') driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '2')
], 0, 1) ],
{
metaDataMessage: 'I am specific to this transfer transaction'
}
);
Because we want to fulfill two outputs (Carly and Bob), we have to sign the transfer transaction in the same order: Because we want to fulfill two outputs (Carly and Bob), we have to sign the transfer transaction in the same order: