Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

97 contract and data types #99

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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