Skip to content

Commit 4184324

Browse files
authored
3.0.0: Refactor Transaction class (#854)
1 parent 2a25f7a commit 4184324

File tree

90 files changed

+5299
-5807
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5299
-5807
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
orbs:
44
node: circleci/node@5.0.0
55
slack: circleci/slack@4.4.2
6-
browser-tools: circleci/browser-tools@1.4.3
6+
browser-tools: circleci/browser-tools@1.4.6
77
gh-pages: sugarshin/gh-pages@1.0.0
88

99
parameters:
@@ -89,7 +89,8 @@ jobs:
8989
$(lsb_release -cs) stable" | $SUDO tee /etc/apt/sources.list.d/docker.list > /dev/null
9090
$SUDO apt update
9191
$SUDO apt -y install docker-ce docker-ce-cli containerd.io
92-
- browser-tools/install-browser-tools
92+
- browser-tools/install-browser-tools:
93+
replace-existing-chrome: true
9394
- run:
9495
name: << parameters.browser >> test
9596
command: |

examples/accounts.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function main() {
1919
const mnemonic =
2020
'creek phrase island true then hope employ veteran rapid hurdle above liberty tissue connect alcohol timber idle ten frog bulb embody crunch taxi abstract month';
2121
const recoveredAccount = algosdk.mnemonicToSecretKey(mnemonic);
22-
console.log('Recovered mnemonic account: ', recoveredAccount.addr);
22+
console.log('Recovered mnemonic account: ', recoveredAccount.addr.toString());
2323
// example: ACCOUNT_RECOVER_MNEMONIC
2424

2525
const funder = accounts[0];
@@ -31,14 +31,14 @@ async function main() {
3131
signerAccounts.push(algosdk.generateAccount());
3232

3333
// multiSigParams is used when creating the address and when signing transactions
34-
const multiSigParams = {
34+
const multiSigParams: algosdk.MultisigMetadata = {
3535
version: 1,
3636
threshold: 2,
3737
addrs: signerAccounts.map((a) => a.addr),
3838
};
3939
const multisigAddr = algosdk.multisigAddress(multiSigParams);
4040

41-
console.log('Created MultiSig Address: ', multisigAddr);
41+
console.log('Created MultiSig Address: ', multisigAddr.toString());
4242
// example: MULTISIG_CREATE
4343

4444
const fundMsigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
@@ -80,7 +80,7 @@ async function main() {
8080
// example: ACCOUNT_GENERATE
8181
const generatedAccount = algosdk.generateAccount();
8282
const passphrase = algosdk.secretKeyToMnemonic(generatedAccount.sk);
83-
console.log(`My address: ${generatedAccount.addr}`);
83+
console.log(`My address: ${generatedAccount.addr.toString()}`);
8484
console.log(`My passphrase: ${passphrase}`);
8585
// example: ACCOUNT_GENERATE
8686

@@ -117,7 +117,7 @@ async function main() {
117117
rekeyTo: acct1.addr,
118118
});
119119
await client.sendRawTransaction(rekeyBack.signTxn(acct2.privateKey)).do();
120-
await algosdk.waitForConfirmation(client, rekeyBack.txID().toString(), 3);
120+
await algosdk.waitForConfirmation(client, rekeyBack.txID(), 3);
121121
}
122122

123123
main();

examples/asa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ async function main() {
114114
sender: manager.addr,
115115
suggestedParams,
116116
assetIndex,
117-
// assetFrozen: false would unfreeze the account's asset holding
118-
assetFrozen: true,
117+
// frozen: false would unfreeze the account's asset holding
118+
frozen: true,
119119
// freezeTarget is the account that is being frozen or unfrozen
120120
freezeTarget: receiver.addr,
121121
});

examples/atomics.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ async function main() {
5151
// example: ATOMIC_GROUP_SEND
5252

5353
// example: CONST_MIN_FEE
54-
const minFee = algosdk.ALGORAND_MIN_TX_FEE;
55-
console.log(minFee);
54+
// This SDK does not expose a constant for the minimum fee
5655
// example: CONST_MIN_FEE
5756

5857
// example: TRANSACTION_FEE_OVERRIDE
5958
const sp = await client.getTransactionParams().do();
60-
sp.fee = 2 * minFee;
59+
sp.fee = BigInt(2) * sp.minFee;
6160
sp.flatFee = true;
6261
// example: TRANSACTION_FEE_OVERRIDE
6362

examples/codec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ async function main() {
1414

1515
// example: CODEC_ADDRESS
1616
const address = '4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4';
17-
const pk = algosdk.decodeAddress(address);
18-
const addr = algosdk.encodeAddress(pk.publicKey);
17+
const addr = algosdk.Address.fromString(address);
1918
console.log(address, addr);
2019
// example: CODEC_ADDRESS
2120

examples/kmd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function main() {
5656

5757
// example: KMD_IMPORT_ACCOUNT
5858
const newAccount = algosdk.generateAccount();
59-
console.log('Account: ', newAccount.addr);
59+
console.log('Account: ', newAccount.addr.toString());
6060
const importedAccount = await kmdClient.importKey(
6161
wallethandle,
6262
newAccount.sk

examples/participation.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ async function main() {
1111
// Parent addr
1212
const addr = 'MWAPNXBDFFD2V5KWXAHWKBO7FO4JN36VR4CIBDKDDE7WAUAGZIXM3QPJW4';
1313
// VRF public key
14-
const selectionKey = 'LrpLhvzr+QpN/bivh6IPpOaKGbGzTTB5lJtVfixmmgk=';
14+
const selectionKey = algosdk.base64ToBytes(
15+
'LrpLhvzr+QpN/bivh6IPpOaKGbGzTTB5lJtVfixmmgk='
16+
);
1517
// Voting pub key
16-
const voteKey = 'G/lqTV6MKspW6J8wH2d8ZliZ5XZVZsruqSBJMwLwlmo=';
18+
const voteKey = algosdk.base64ToBytes(
19+
'G/lqTV6MKspW6J8wH2d8ZliZ5XZVZsruqSBJMwLwlmo='
20+
);
1721
// State proof key
18-
const stateProofKey =
19-
'RpUpNWfZMjZ1zOOjv3MF2tjO714jsBt0GKnNsw0ihJ4HSZwci+d9zvUi3i67LwFUJgjQ5Dz4zZgHgGduElnmSA==';
22+
const stateProofKey = algosdk.base64ToBytes(
23+
'RpUpNWfZMjZ1zOOjv3MF2tjO714jsBt0GKnNsw0ihJ4HSZwci+d9zvUi3i67LwFUJgjQ5Dz4zZgHgGduElnmSA=='
24+
);
2025

21-
// sets up keys for 100000 rounds
22-
const numRounds = 1e5;
26+
// sets up keys for 100,000 rounds
27+
const numRounds = 100_000;
2328

2429
// dilution default is sqrt num rounds
25-
const keyDilution = numRounds ** 0.5;
30+
const keyDilution = Math.floor(Math.sqrt(numRounds));
2631

2732
// create transaction
2833
const onlineKeyreg =
@@ -32,7 +37,7 @@ async function main() {
3237
selectionKey,
3338
stateProofKey,
3439
voteFirst: params.firstValid,
35-
voteLast: params.firstValid + numRounds,
40+
voteLast: params.firstValid + BigInt(numRounds),
3641
voteKeyDilution: keyDilution,
3742
suggestedParams: params,
3843
});

examples/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function getLocalAlgodClient() {
4545
}
4646

4747
export interface SandboxAccount {
48-
addr: string;
48+
addr: algosdk.Address;
4949
privateKey: Uint8Array;
5050
signer: algosdk.TransactionSigner;
5151
}
@@ -81,8 +81,8 @@ export async function getLocalAccounts(): Promise<SandboxAccount[]> {
8181
kmdClient.releaseWalletHandle(handle);
8282

8383
return keys.map((k) => {
84-
const addr = algosdk.encodeAddress(k.private_key.slice(32));
85-
const acct = { sk: k.private_key, addr } as algosdk.Account;
84+
const addr = new algosdk.Address(k.private_key.slice(32));
85+
const acct: algosdk.Account = { sk: k.private_key, addr };
8686
const signer = algosdk.makeBasicAccountTransactionSigner(acct);
8787

8888
return {

src/account.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as nacl from './nacl/naclWrappers.js';
2-
import * as address from './encoding/address.js';
2+
import { Address } from './encoding/address.js';
33
import Account from './types/account.js';
44

55
/**
66
* generateAccount returns a new Algorand address and its corresponding secret key
77
*/
88
export default function generateAccount(): Account {
99
const keys = nacl.keyPair();
10-
const encodedPk = address.encodeAddress(keys.publicKey);
11-
return { addr: encodedPk, sk: keys.secretKey };
10+
const addr = new Address(keys.publicKey);
11+
return { addr, sk: keys.secretKey };
1212
}

src/bid.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)