Skip to content

Commit

Permalink
Align transaction fields to transaction reference spec (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
algochoi authored Aug 11, 2023
1 parent 81ab6eb commit c079c61
Show file tree
Hide file tree
Showing 32 changed files with 891 additions and 880 deletions.
16 changes: 8 additions & 8 deletions examples/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ async function main() {
// example: MULTISIG_CREATE

const fundMsigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: funder.addr,
to: multisigAddr,
sender: funder.addr,
receiver: multisigAddr,
amount: 1_000_000,
suggestedParams,
});
Expand All @@ -53,8 +53,8 @@ async function main() {

// example: MULTISIG_SIGN
const msigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: multisigAddr,
to: funder.addr,
sender: multisigAddr,
receiver: funder.addr,
amount: 100,
suggestedParams,
});
Expand Down Expand Up @@ -88,8 +88,8 @@ async function main() {
// rekey the original account to the new signer via a payment transaction
// Note any transaction type can be used to rekey an account
const rekeyTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct1.addr,
to: acct1.addr,
sender: acct1.addr,
receiver: acct1.addr,
amount: 0,
suggestedParams,
rekeyTo: acct2.addr, // set the rekeyTo field to the new signer
Expand All @@ -110,8 +110,8 @@ async function main() {
// the transaction is from originalAccount, but signed with newSigner private key

const rekeyBack = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct1.addr,
to: acct1.addr,
sender: acct1.addr,
receiver: acct1.addr,
amount: 0,
suggestedParams,
rekeyTo: acct1.addr,
Expand Down
18 changes: 9 additions & 9 deletions examples/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function main() {

// example: APP_CREATE
const appCreateTxn = algosdk.makeApplicationCreateTxnFromObject({
from: creator.addr,
sender: creator.addr,
approvalProgram: new Uint8Array(compiledApprovalProgram),
clearProgram: new Uint8Array(compiledClearProgram),
numGlobalByteSlices,
Expand Down Expand Up @@ -78,7 +78,7 @@ async function main() {

// example: APP_OPTIN
const appOptInTxn = algosdk.makeApplicationOptInTxnFromObject({
from: caller.addr,
sender: caller.addr,
appIndex: appId,
suggestedParams,
});
Expand All @@ -95,7 +95,7 @@ async function main() {

// example: APP_NOOP
const appNoOpTxn = algosdk.makeApplicationNoOpTxnFromObject({
from: caller.addr,
sender: caller.addr,
appIndex: appId,
suggestedParams,
});
Expand All @@ -113,7 +113,7 @@ async function main() {
const anotherCaller = accounts[2];

const anotherAppOptInTxn = algosdk.makeApplicationOptInTxnFromObject({
from: anotherCaller.addr,
sender: anotherCaller.addr,
appIndex: appId,
suggestedParams,
});
Expand All @@ -130,7 +130,7 @@ async function main() {
// example: APP_CALL
const now = new Date().toString();
const simpleAddTxn = algosdk.makeApplicationNoOpTxnFromObject({
from: caller.addr,
sender: caller.addr,
suggestedParams,
appIndex: appId,
appArgs: [new TextEncoder().encode(now)],
Expand Down Expand Up @@ -175,7 +175,7 @@ async function main() {

// example: APP_CLOSEOUT
const appCloseOutTxn = algosdk.makeApplicationCloseOutTxnFromObject({
from: caller.addr,
sender: caller.addr,
appIndex: appId,
suggestedParams,
});
Expand All @@ -198,7 +198,7 @@ async function main() {
const compiledNewProgram = await compileProgram(algodClient, newProgram);

const appUpdateTxn = algosdk.makeApplicationUpdateTxnFromObject({
from: creator.addr,
sender: creator.addr,
suggestedParams,
appIndex: appId,
// updates must define both approval and clear programs, even if unchanged
Expand All @@ -218,7 +218,7 @@ async function main() {

// example: APP_CLEAR
const appClearTxn = algosdk.makeApplicationClearStateTxnFromObject({
from: anotherCaller.addr,
sender: anotherCaller.addr,
suggestedParams,
appIndex: appId,
});
Expand All @@ -235,7 +235,7 @@ async function main() {

// example: APP_DELETE
const appDeleteTxn = algosdk.makeApplicationDeleteTxnFromObject({
from: creator.addr,
sender: creator.addr,
suggestedParams,
appIndex: appId,
});
Expand Down
32 changes: 16 additions & 16 deletions examples/asa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main() {
// example: ASSET_CREATE
const suggestedParams = await algodClient.getTransactionParams().do();
const txn = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({
from: creator.addr,
sender: creator.addr,
suggestedParams,
defaultFrozen: false,
unitName: 'rug',
Expand Down Expand Up @@ -61,7 +61,7 @@ async function main() {
const manager = accounts[1];

const configTxn = algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject({
from: creator.addr,
sender: creator.addr,
manager: manager.addr,
freeze: manager.addr,
clawback: manager.addr,
Expand All @@ -87,8 +87,8 @@ async function main() {

// opt-in is simply a 0 amount transfer of the asset to oneself
const optInTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: receiver.addr,
to: receiver.addr,
sender: receiver.addr,
receiver: receiver.addr,
suggestedParams,
assetIndex,
amount: 0,
Expand All @@ -101,8 +101,8 @@ async function main() {

// example: ASSET_XFER
const xferTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: creator.addr,
to: receiver.addr,
sender: creator.addr,
receiver: receiver.addr,
suggestedParams,
assetIndex,
amount: 1,
Expand All @@ -115,11 +115,11 @@ async function main() {

// example: ASSET_FREEZE
const freezeTxn = algosdk.makeAssetFreezeTxnWithSuggestedParamsFromObject({
from: manager.addr,
sender: manager.addr,
suggestedParams,
assetIndex,
// freezeState: false would unfreeze the account's asset holding
freezeState: true,
// assetFrozen: false would unfreeze the account's asset holding
assetFrozen: true,
// freezeTarget is the account that is being frozen or unfrozen
freezeTarget: receiver.addr,
});
Expand All @@ -136,10 +136,10 @@ async function main() {
// example: ASSET_CLAWBACK
const clawbackTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject(
{
from: manager.addr,
to: creator.addr,
// revocationTarget is the account that is being clawed back from
revocationTarget: receiver.addr,
sender: manager.addr,
receiver: creator.addr,
// assetSender is the account that is being clawed back from
assetSender: receiver.addr,
suggestedParams,
assetIndex,
amount: 1,
Expand All @@ -161,8 +161,8 @@ async function main() {
// any account that can receive the asset.
// note that closing to the asset creator will always succeed
const optOutTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: receiver.addr,
to: creator.addr,
sender: receiver.addr,
receiver: creator.addr,
closeRemainderTo: creator.addr,
suggestedParams,
assetIndex,
Expand All @@ -180,7 +180,7 @@ async function main() {

// example: ASSET_DELETE
const deleteTxn = algosdk.makeAssetDestroyTxnWithSuggestedParamsFromObject({
from: manager.addr,
sender: manager.addr,
suggestedParams,
assetIndex,
});
Expand Down
6 changes: 3 additions & 3 deletions examples/atc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function main() {
const compiledClearProgram = await compileProgram(client, clearProgram);

const createTxn = algosdk.makeApplicationCreateTxnFromObject({
from: sender.addr,
sender: sender.addr,
suggestedParams,
onComplete: algosdk.OnApplicationComplete.NoOpOC,
approvalProgram: compiledApprovalProgram,
Expand Down Expand Up @@ -61,9 +61,9 @@ async function main() {
// example: ATC_ADD_TRANSACTION
// construct a transaction
const paymentTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: sender.addr,
sender: sender.addr,
suggestedParams,
to: sender.addr,
receiver: sender.addr,
amount: 1000,
});

Expand Down
8 changes: 4 additions & 4 deletions examples/atomics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ async function main() {
const suggestedParams = await client.getTransactionParams().do();

const alicesTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct1.addr,
to: acct2.addr,
sender: acct1.addr,
receiver: acct2.addr,
amount: 1e6,
suggestedParams,
});

const bobsTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct2.addr,
to: acct1.addr,
sender: acct2.addr,
receiver: acct1.addr,
amount: 1e6,
suggestedParams,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function main() {

// example: CODEC_TRANSACTION_UNSIGNED
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: sender.addr,
to: receiver.addr,
sender: sender.addr,
receiver: receiver.addr,
amount: 1e6,
suggestedParams,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ async function main() {
const sender = accounts[0];

const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: sender.addr,
to: sender.addr,
sender: sender.addr,
receiver: sender.addr,
amount: 1e6,
note: new TextEncoder().encode('Hello World!'),
suggestedParams,
Expand Down
12 changes: 6 additions & 6 deletions examples/lsig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ async function main() {
// example: LSIG_PASS_ARGS

const fundSmartSigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: funder.addr,
to: smartSig.address(),
sender: funder.addr,
receiver: smartSig.address(),
amount: 1e6,
suggestedParams,
});
Expand All @@ -50,8 +50,8 @@ async function main() {

// example: LSIG_SIGN_FULL
const smartSigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: smartSig.address(),
to: funder.addr,
sender: smartSig.address(),
receiver: funder.addr,
amount: 0.1e6,
suggestedParams,
});
Expand All @@ -72,8 +72,8 @@ async function main() {
smartSig.sign(userAccount.privateKey);

const delegatedTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: userAccount.addr,
to: funder.addr,
sender: userAccount.addr,
receiver: funder.addr,
amount: 0.1e6,
suggestedParams,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ async function main() {
// example: TRANSACTION_PAYMENT_CREATE
const suggestedParams = await algodClient.getTransactionParams().do();
const ptxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct.addr,
sender: acct.addr,
suggestedParams,
to: acct2.addr,
receiver: acct2.addr,
amount: 10000,
note: new TextEncoder().encode('hello world'),
});
Expand Down
8 changes: 4 additions & 4 deletions examples/participation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ async function main() {
// create transaction
const onlineKeyreg = algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject(
{
from: addr,
sender: addr,
voteKey,
selectionKey,
stateProofKey,
voteFirst: params.firstRound,
voteLast: params.firstRound + numRounds,
voteFirst: params.firstValid,
voteLast: params.firstValid + numRounds,
voteKeyDilution: keyDilution,
suggestedParams: params,
}
Expand All @@ -47,7 +47,7 @@ async function main() {
// create keyreg transaction to take this account offline
const offlineKeyReg = algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject(
{
from: addr,
sender: addr,
suggestedParams,
nonParticipation: true,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function deployCalculatorApp(
const clearBin = await compileProgram(algodClient, clearProgram);
const suggestedParams = await algodClient.getTransactionParams().do();
const appCreateTxn = algosdk.makeApplicationCreateTxnFromObject({
from: creator.addr,
sender: creator.addr,
approvalProgram: approvalBin,
clearProgram: clearBin,
numGlobalByteSlices: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/client/v2/algod/algod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ export default class AlgodClient extends ServiceClient {
* const suggestedParams = await algodClient.getTransactionParams().do();
* const amountInMicroAlgos = algosdk.algosToMicroalgos(2); // 2 Algos
* const unsignedTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
* from: senderAddress,
* to: receiverAddress,
* sender: senderAddress,
* receiver: receiverAddress,
* amount: amountInMicroAlgos,
* suggestedParams: suggestedParams,
* });
Expand Down
4 changes: 2 additions & 2 deletions src/client/v2/algod/suggestedParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class SuggestedParamsRequest extends JSONRequest<SuggestedParamsW
return {
flatFee: false,
fee: body.fee,
firstRound: body['last-round'],
lastRound: body['last-round'] + 1000,
firstValid: body['last-round'],
lastValid: body['last-round'] + 1000,
genesisID: body['genesis-id'],
genesisHash: body['genesis-hash'],
minFee: body['min-fee'],
Expand Down
2 changes: 1 addition & 1 deletion src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class AtomicTransactionComposer {

const appCall = {
txn: makeApplicationCallTxnFromObject({
from: sender,
sender,
appIndex: appID,
appArgs: appArgsEncoded,
accounts: foreignAccounts,
Expand Down
Loading

0 comments on commit c079c61

Please sign in to comment.