Skip to content

Commit

Permalink
97 contract and data types (#99)
Browse files Browse the repository at this point in the history
* add transaction types: contract and data

* add unit test

* fix typo
  • Loading branch information
bchamagne committed Jan 13, 2023
1 parent bb11acb commit 117012b
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 199 deletions.
44 changes: 22 additions & 22 deletions dist/archethic-browser.mjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/archethic-browser.mjs.map

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions dist/archethic-node.mjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/archethic-node.mjs.map

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions dist/archethic.cjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/archethic.cjs.map

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions dist/archethic.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/archethic.js.map

Large diffs are not rendered by default.

99 changes: 0 additions & 99 deletions dist/archethic.mjs

This file was deleted.

7 changes: 0 additions & 7 deletions dist/archethic.mjs.map

This file was deleted.

4 changes: 3 additions & 1 deletion example/transactionBuilder/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ <h1 class="is-size-5 has-text-white">Transaction Builder</h1>
<option value="transfer">Transfer</option>
<option value="hosting">Hosting</option>
<option value="token">Token</option>
<option value="data">Data</option>
<option value="contract">Contract</option>
</select>
</div>
<div class="box">
Expand Down Expand Up @@ -138,4 +140,4 @@ <h1 class="is-size-5 has-text-white">Transaction Builder</h1>
<script src="dist/app.js"></script>
</body>

</html>
</html>
8 changes: 5 additions & 3 deletions lib/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const txTypes = {
"transfer": 253,
"hosting": 252,
"token": 251,
"data": 250,
"contract": 249,
//Network based transaction types
"code_proposal": 7,
"code_approval": 8
Expand Down Expand Up @@ -45,7 +47,7 @@ export default class TransactionBuilder {
*/
setType(type) {
if (!Object.keys(txTypes).includes(type)) {
throw "Transaction type must be 'transfer', 'hosting', 'keychain_access', 'keychain', 'token', 'code_proposal', 'code_approval'"
throw "Transaction type must be in " + Object.keys(txTypes).map(t => `'${t}'`).join(", ")
}
this.type = type
return this
Expand Down Expand Up @@ -131,7 +133,7 @@ export default class TransactionBuilder {

if (acc[publicKey]) return acc

filteredAuthorizedKeys.push({publicKey, encryptedSecretKey})
filteredAuthorizedKeys.push({ publicKey, encryptedSecretKey })

acc[publicKey] = encryptedSecretKey

Expand Down Expand Up @@ -167,7 +169,7 @@ export default class TransactionBuilder {
throw 'UCO transfer amount must be a positive number'
}

this.data.ledger.uco.transfers.push({to, amount})
this.data.ledger.uco.transfers.push({ to, amount })
return this
}

Expand Down
18 changes: 17 additions & 1 deletion test/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,26 @@ import assert from "assert";

describe("Transaction builder", () => {
describe("setType", () => {
it("should assign type", () => {
it("should assign type transfer", () => {
const tx = new TransactionBuilder().setType("transfer");
assert.strictEqual(tx.type, "transfer");
});
it("should assign type contract", () => {
const tx = new TransactionBuilder().setType("contract");
assert.strictEqual(tx.type, "contract");
});
it("should assign type data", () => {
const tx = new TransactionBuilder().setType("data");
assert.strictEqual(tx.type, "data");
});
it("should assign type token", () => {
const tx = new TransactionBuilder().setType("token");
assert.strictEqual(tx.type, "token");
});
it("should assign type hosting", () => {
const tx = new TransactionBuilder().setType("hosting");
assert.strictEqual(tx.type, "hosting");
});
});

describe("setCode", () => {
Expand Down

0 comments on commit 117012b

Please sign in to comment.