Skip to content

Commit 1290913

Browse files
author
Andy Haynes
committed
--wip-- [skip ci]
1 parent afd3392 commit 1290913

File tree

4 files changed

+168
-168
lines changed

4 files changed

+168
-168
lines changed

packages/client/src/interfaces/dependencies.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {
2-
BlockReference,
3-
BlockResult,
4-
FinalExecutionOutcome,
5-
QueryResponseKind,
2+
BlockReference,
3+
BlockResult,
4+
FinalExecutionOutcome,
5+
QueryResponseKind,
66
} from '@near-js/types';
77
import type { SignedTransaction } from '@near-js/transactions';
88
import type { PublicKey } from '@near-js/crypto';

packages/client/src/transactions/actions.ts

+35-35
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,52 @@ import { signAndSendFromComposer } from './sign_and_send';
44
import { AddFunctionCallAccessKeyParams, SignAndSendNonceParams } from '../interfaces';
55

66
async function getComposerResult({ composer, nonce, blockReference, deps }: { composer: TransactionComposer } & SignAndSendNonceParams) {
7-
const { result } = await signAndSendFromComposer({
8-
composer,
9-
nonce,
10-
blockReference,
11-
deps,
12-
});
7+
const { result } = await signAndSendFromComposer({
8+
composer,
9+
nonce,
10+
blockReference,
11+
deps,
12+
});
1313

14-
return result;
14+
return result;
1515
}
1616

1717
export async function functionCall({ sender, receiver, method, args, gas, deposit, nonce, blockReference, deps }: FunctionCallParams) {
18-
return getComposerResult({
19-
composer: TransactionComposer.init({ sender, receiver })
20-
.functionCall(method, args, gas, deposit),
21-
nonce,
22-
blockReference,
23-
deps,
24-
});
18+
return getComposerResult({
19+
composer: TransactionComposer.init({ sender, receiver })
20+
.functionCall(method, args, gas, deposit),
21+
nonce,
22+
blockReference,
23+
deps,
24+
});
2525
}
2626

2727
export async function transfer({ sender, receiver, amount, nonce, blockReference, deps }: TransferParams) {
28-
return getComposerResult({
29-
composer: TransactionComposer.init({ sender, receiver })
30-
.transfer(amount),
31-
nonce,
32-
blockReference,
33-
deps,
34-
});
28+
return getComposerResult({
29+
composer: TransactionComposer.init({ sender, receiver })
30+
.transfer(amount),
31+
nonce,
32+
blockReference,
33+
deps,
34+
});
3535
}
3636

3737
export async function addFullAccessKey({ account, publicKey, nonce, blockReference, deps }: AddFullAccessKeyParams) {
38-
return getComposerResult({
39-
composer: TransactionComposer.init({ sender: account, receiver: account })
40-
.addFullAccessKey(publicKey),
41-
nonce,
42-
blockReference,
43-
deps,
44-
});
38+
return getComposerResult({
39+
composer: TransactionComposer.init({ sender: account, receiver: account })
40+
.addFullAccessKey(publicKey),
41+
nonce,
42+
blockReference,
43+
deps,
44+
});
4545
}
4646

4747
export async function addFunctionCallAccessKey({ account, publicKey, contract, methodNames, allowance, nonce, blockReference, deps }: AddFunctionCallAccessKeyParams) {
48-
return getComposerResult({
49-
composer: TransactionComposer.init({ sender: account, receiver: account })
50-
.addFunctionCallAccessKey(publicKey, contract, methodNames, allowance),
51-
nonce,
52-
blockReference,
53-
deps,
54-
});
48+
return getComposerResult({
49+
composer: TransactionComposer.init({ sender: account, receiver: account })
50+
.addFunctionCallAccessKey(publicKey, contract, methodNames, allowance),
51+
nonce,
52+
blockReference,
53+
deps,
54+
});
5555
}
+88-88
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { PublicKey } from '@near-js/crypto';
22
import {
3-
Action,
4-
actionCreators,
5-
buildDelegateAction,
6-
DelegateAction,
7-
Signature,
8-
Transaction,
3+
Action,
4+
actionCreators,
5+
buildDelegateAction,
6+
DelegateAction,
7+
Signature,
8+
Transaction,
99
} from '@near-js/transactions';
1010
import { baseDecode, DEFAULT_FUNCTION_CALL_GAS } from '@near-js/utils';
1111
import { DEFAULT_META_TRANSACTION_BLOCK_HEIGHT_TTL } from '../constants';
@@ -20,102 +20,102 @@ interface TransactionOptions {
2020
}
2121

2222
export class TransactionComposer {
23-
private actions: Action[] = [];
24-
receiver: string | undefined;
25-
sender: string | undefined;
26-
blockHeader: BlockHeader | undefined;
27-
nonce: bigint | undefined;
28-
publicKey: PublicKey | undefined;
23+
private actions: Action[] = [];
24+
receiver: string | undefined;
25+
sender: string | undefined;
26+
blockHeader: BlockHeader | undefined;
27+
nonce: bigint | undefined;
28+
publicKey: PublicKey | undefined;
2929

30-
static init(transaction: TransactionOptions) {
31-
const composer = new TransactionComposer();
32-
composer.receiver = transaction.receiver;
33-
composer.sender = transaction.sender;
34-
composer.blockHeader = transaction.blockHeader;
35-
composer.nonce = transaction.nonce;
36-
composer.publicKey = transaction.publicKey;
30+
static init(transaction: TransactionOptions) {
31+
const composer = new TransactionComposer();
32+
composer.receiver = transaction.receiver;
33+
composer.sender = transaction.sender;
34+
composer.blockHeader = transaction.blockHeader;
35+
composer.nonce = transaction.nonce;
36+
composer.publicKey = transaction.publicKey;
3737

38-
return composer;
39-
}
38+
return composer;
39+
}
4040

41-
private buildTransactionObject(transaction?: TransactionOptions) {
42-
const hash = (transaction?.blockHeader?.hash || this.blockHeader?.hash)!;
43-
return {
44-
actions: this.actions,
45-
blockHash: baseDecode(hash),
46-
nonce: (transaction?.nonce || this.nonce)!,
47-
publicKey: (transaction?.publicKey || this.publicKey)!,
48-
receiverId: (transaction?.receiver || this.receiver)!,
49-
signerId: (transaction?.sender || this.sender)!,
50-
};
51-
}
41+
private buildTransactionObject(transaction?: TransactionOptions) {
42+
const hash = (transaction?.blockHeader?.hash || this.blockHeader?.hash)!;
43+
return {
44+
actions: this.actions,
45+
blockHash: baseDecode(hash),
46+
nonce: (transaction?.nonce || this.nonce)!,
47+
publicKey: (transaction?.publicKey || this.publicKey)!,
48+
receiverId: (transaction?.receiver || this.receiver)!,
49+
signerId: (transaction?.sender || this.sender)!,
50+
};
51+
}
5252

53-
toTransaction(transaction?: TransactionOptions): Transaction {
54-
return new Transaction(this.buildTransactionObject(transaction));
55-
}
53+
toTransaction(transaction?: TransactionOptions): Transaction {
54+
return new Transaction(this.buildTransactionObject(transaction));
55+
}
5656

57-
toDelegateAction(transaction?: TransactionOptions): DelegateAction {
58-
const { actions, nonce, publicKey, receiverId, signerId } = this.buildTransactionObject(transaction);
59-
const blockHeader = transaction?.blockHeader || this.blockHeader;
57+
toDelegateAction(transaction?: TransactionOptions): DelegateAction {
58+
const { actions, nonce, publicKey, receiverId, signerId } = this.buildTransactionObject(transaction);
59+
const blockHeader = transaction?.blockHeader || this.blockHeader;
6060

61-
return buildDelegateAction({
62-
actions,
63-
maxBlockHeight: BigInt(blockHeader!.height) + DEFAULT_META_TRANSACTION_BLOCK_HEIGHT_TTL,
64-
nonce: BigInt(nonce) + BigInt(1),
65-
publicKey,
66-
receiverId,
67-
senderId: signerId,
68-
});
69-
}
61+
return buildDelegateAction({
62+
actions,
63+
maxBlockHeight: BigInt(blockHeader!.height) + DEFAULT_META_TRANSACTION_BLOCK_HEIGHT_TTL,
64+
nonce: BigInt(nonce) + BigInt(1),
65+
publicKey,
66+
receiverId,
67+
senderId: signerId,
68+
});
69+
}
7070

71-
addFullAccessKey(publicKey: PublicKey) {
72-
this.actions.push(actionCreators.addKey(publicKey, actionCreators.fullAccessKey()));
73-
return this;
74-
}
71+
addFullAccessKey(publicKey: PublicKey) {
72+
this.actions.push(actionCreators.addKey(publicKey, actionCreators.fullAccessKey()));
73+
return this;
74+
}
7575

76-
addFunctionCallAccessKey(publicKey: PublicKey, contractId: string, methodNames: string[], allowance?: bigint) {
77-
const accessKey = actionCreators.functionCallAccessKey(contractId, methodNames, allowance)
78-
this.actions.push(actionCreators.addKey(publicKey, accessKey));
79-
return this;
80-
}
76+
addFunctionCallAccessKey(publicKey: PublicKey, contractId: string, methodNames: string[], allowance?: bigint) {
77+
const accessKey = actionCreators.functionCallAccessKey(contractId, methodNames, allowance);
78+
this.actions.push(actionCreators.addKey(publicKey, accessKey));
79+
return this;
80+
}
8181

82-
createAccount() {
83-
this.actions.push(actionCreators.createAccount());
84-
return this;
85-
}
82+
createAccount() {
83+
this.actions.push(actionCreators.createAccount());
84+
return this;
85+
}
8686

87-
deleteAccount(beneficiaryId: string) {
88-
this.actions.push(actionCreators.deleteAccount(beneficiaryId));
89-
return this;
90-
}
87+
deleteAccount(beneficiaryId: string) {
88+
this.actions.push(actionCreators.deleteAccount(beneficiaryId));
89+
return this;
90+
}
9191

92-
deleteKey(publicKey: PublicKey) {
93-
this.actions.push(actionCreators.deleteKey(publicKey));
94-
return this;
95-
}
92+
deleteKey(publicKey: PublicKey) {
93+
this.actions.push(actionCreators.deleteKey(publicKey));
94+
return this;
95+
}
9696

97-
deployContract(code: Uint8Array) {
98-
this.actions.push(actionCreators.deployContract(code));
99-
return this;
100-
}
97+
deployContract(code: Uint8Array) {
98+
this.actions.push(actionCreators.deployContract(code));
99+
return this;
100+
}
101101

102-
functionCall(method: string, args: object, gas: bigint = DEFAULT_FUNCTION_CALL_GAS * BigInt(10), deposit = BigInt(0)) {
103-
this.actions.push(actionCreators.functionCall(method, args, gas, deposit));
104-
return this;
105-
}
102+
functionCall(method: string, args: object, gas: bigint = DEFAULT_FUNCTION_CALL_GAS * BigInt(10), deposit = BigInt(0)) {
103+
this.actions.push(actionCreators.functionCall(method, args, gas, deposit));
104+
return this;
105+
}
106106

107-
signedDelegate(delegateAction: DelegateAction, signature: Signature) {
108-
this.actions.push(actionCreators.signedDelegate({ delegateAction, signature }));
109-
return this;
110-
}
107+
signedDelegate(delegateAction: DelegateAction, signature: Signature) {
108+
this.actions.push(actionCreators.signedDelegate({ delegateAction, signature }));
109+
return this;
110+
}
111111

112-
stake(stake: bigint, publicKey: PublicKey) {
113-
this.actions.push(actionCreators.stake(stake, publicKey));
114-
return this;
115-
}
112+
stake(stake: bigint, publicKey: PublicKey) {
113+
this.actions.push(actionCreators.stake(stake, publicKey));
114+
return this;
115+
}
116116

117-
transfer(deposit: bigint) {
118-
this.actions.push(actionCreators.transfer(deposit));
119-
return this;
120-
}
117+
transfer(deposit: bigint) {
118+
this.actions.push(actionCreators.transfer(deposit));
119+
return this;
120+
}
121121
}

0 commit comments

Comments
 (0)