Skip to content

Commit

Permalink
Rename transfer() in Asset to createTransferTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
joojis committed Jul 20, 2018
1 parent 43c6bc5 commit 8dbbe26
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
16 changes: 9 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ Then, the AssetMintTransaction is processed with the following code:
Alice then sends 3000 gold to Bob. In CodeChain, users must follow the [UTXO](https://codechain.readthedocs.io/en/latest/what-is-codechain.html#what-is-utxo) standard, and make a transaction that spends an entire UTXO balance, and receive the change back through another transaction.
```javascript
// The sum of amount must equal to the amount of firstGold.
const transferTx = firstGold.transfer([{
address: bobAddress,
amount: 3000
}, {
address: aliceAddress,
amount: 7000
}]);
const transferTx = firstGold.createTransferTransaction({
recipients: [{
address: bobAddress,
amount: 3000
}, {
address: aliceAddress,
amount: 7000
}]
});
```
By using Alice's signature, the 10000 Gold that was first minted can now be transferred to other users like Bob.
```javascript
Expand Down
16 changes: 9 additions & 7 deletions examples/mint-and-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ async function sendTransaction(tx) {

const firstGold = await sdk.rpc.chain.getAsset(mintTx.hash(), 0);

const transferTx = firstGold.transfer([{
address: bobAddress,
amount: 3000
}, {
address: aliceAddress,
amount: 7000
}]);
const transferTx = firstGold.createTransferTransaction({
recipients: [{
address: bobAddress,
amount: 3000
}, {
address: aliceAddress,
amount: 7000
}]
});
await sdk.key.unlock(transferTx, 0);

await sendTransaction(transferTx);
Expand Down
10 changes: 6 additions & 4 deletions integration_tests/Transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ test("AssetTransferTransaction fromJSON", async () => {
await sendTransactions({ transactions: [mintTx] });
const firstAsset = await sdk.rpc.chain.getAsset(mintTx.hash(), 0);

const transferTx = await firstAsset.transfer([{
address: addressB,
amount: 100
}]);
const transferTx = await firstAsset.createTransferTransaction({
recipients: [{
address: addressB,
amount: 100
}]
});
await sdk.key.unlock(transferTx, 0);
const { parcelHash } = await sendTransactions({ transactions: [transferTx] });
const parcel = await sdk.rpc.chain.getParcel(parcelHash);
Expand Down
4 changes: 2 additions & 2 deletions src/core/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class Asset {
};
}

transfer(recipients: { address: AssetTransferAddress, amount: number }[], options: { nonce?: number } = {}): AssetTransferTransaction {
createTransferTransaction(params: { recipients: { address: AssetTransferAddress, amount: number }[], nonce?: number }): AssetTransferTransaction {
const { outPoint, assetType } = this;
const { nonce = 0 } = options;
const { recipients, nonce = 0 } = params;

const outputSum = recipients.map(r => r.amount).reduce((a, b) => a + b);
if (outputSum !== this.amount) {
Expand Down
2 changes: 1 addition & 1 deletion src/key/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Key {

/**
* Creates AssetTransferAddress for the standard P2PKH asset.
* To use this address, see AssetScheme.createMintTransaction() or Asset.transfer().
* To use this address, see AssetScheme.createMintTransaction() or Asset.createTransferTransaction().
* @returns AssetTransferAddress
*/
createPubKeyHashAddress(): Promise<AssetTransferAddress> {
Expand Down

0 comments on commit 8dbbe26

Please sign in to comment.