Skip to content

Commit

Permalink
Merge pull request #1005 from near/revert-1002-NAJ-44-make-sign-and-s…
Browse files Browse the repository at this point in the history
…end-transaction-functionality-public

Revert "Naj 44 make sign and send transaction functionality public"
  • Loading branch information
morgsmccauley authored Oct 3, 2022
2 parents a330763 + 2a84007 commit e07d1ca
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 33 deletions.
5 changes: 0 additions & 5 deletions .changeset/beige-suits-march.md

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#IDE
.idea
.vscode

storage
node_modules
Expand Down
2 changes: 1 addition & 1 deletion packages/near-api-js/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class Account {
* Sign a transaction to preform a list of actions and broadcast it using the RPC API.
* @see {@link providers/json-rpc-provider!JsonRpcProvider#sendTransaction | JsonRpcProvider.sendTransaction}
*/
async signAndSendTransaction({ receiverId, actions, returnError }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
protected async signAndSendTransaction({ receiverId, actions, returnError }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
let txHash, signedTx;
// TODO: TX_NONCE (different constants for different uses of exponentialBackoff?)
const result = await exponentialBackoff(TX_NONCE_RETRY_WAIT, TX_NONCE_RETRY_NUMBER, TX_NONCE_RETRY_WAIT_BACKOFF, async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/near-api-js/src/account_multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AccountMultisig extends Account {
return super.signAndSendTransaction({ receiverId, actions });
}

async signAndSendTransaction({ receiverId, actions }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
protected async signAndSendTransaction({ receiverId, actions }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
const { accountId } = this;

const args = Buffer.from(JSON.stringify({
Expand Down Expand Up @@ -234,7 +234,7 @@ export class Account2FA extends AccountMultisig {
* Sign a transaction to preform a list of actions and broadcast it using the RPC API.
* @see {@link providers/json-rpc-provider!JsonRpcProvider#sendTransaction | JsonRpcProvider.sendTransaction}
*/
async signAndSendTransaction({ receiverId, actions }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
protected async signAndSendTransaction({ receiverId, actions }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
await super.signAndSendTransaction({ receiverId, actions });
// TODO: Should following override onRequestResult in superclass instead of doing custom signAndSendTransaction?
await this.sendCode();
Expand Down
2 changes: 1 addition & 1 deletion packages/near-api-js/src/wallet-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class ConnectedWalletAccount extends Account {
* Sign a transaction by redirecting to the NEAR Wallet
* @see {@link WalletConnection.requestSignTransactions}
*/
async signAndSendTransaction({ receiverId, actions, walletMeta, walletCallbackUrl = window.location.href }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
protected async signAndSendTransaction({ receiverId, actions, walletMeta, walletCallbackUrl = window.location.href }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
const localKey = await this.connection.signer.getPublicKey(this.accountId, this.connection.networkId);
let accessKey = await this.accessKeyForTransaction(receiverId, actions, localKey);
if (!accessKey) {
Expand Down
10 changes: 0 additions & 10 deletions packages/near-api-js/test/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const testUtils = require('./test-utils');
const { TypedError } = require('../src/utils/errors');
const fs = require('fs');
const BN = require('bn.js');
const { transfer } = require('../src/transaction');

let nearjs;
let workingAccount;
Expand Down Expand Up @@ -47,15 +46,6 @@ test('send money', async() => {
expect(state.amount).toEqual(new BN(receiverAmount).add(new BN(10000)).toString());
});

test('send money through signAndSendTransaction', async() => {
const sender = await testUtils.createAccount(nearjs);
const receiver = await testUtils.createAccount(nearjs);
const { amount: receiverAmount } = await receiver.state();
await sender.signAndSendTransaction({receiverId: receiver.accountId, actions: [transfer(new BN(10000))]});
const state = await receiver.state();
expect(state.amount).toEqual(new BN(receiverAmount).add(new BN(10000)).toString());
});

test('delete account', async() => {
const sender = await testUtils.createAccount(nearjs);
const receiver = await testUtils.createAccount(nearjs);
Expand Down
14 changes: 1 addition & 13 deletions packages/near-api-js/test/account_multisig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const fs = require('fs');
const BN = require('bn.js');
const testUtils = require('./test-utils');
const semver = require('semver');
const { transfer } = require('../src/transaction');

let nearjs;
let startFromVersion;
Expand Down Expand Up @@ -120,16 +119,5 @@ describe('account2fa transactions', () => {
const state = await receiver.state();
expect(BigInt(state.amount)).toBeGreaterThanOrEqual(BigInt(new BN(receiverAmount).add(new BN(parseNearAmount('0.9'))).toString()));
});

test('send money through signAndSendTransaction', async() => {
let sender = await testUtils.createAccount(nearjs);
let receiver = await testUtils.createAccount(nearjs);
sender = await getAccount2FA(sender);
receiver = await getAccount2FA(receiver);
const { amount: receiverAmount } = await receiver.state();
await sender.signAndSendTransaction({receiverId: receiver.accountId, actions: [transfer(new BN(parseNearAmount('1')))]});
const state = await receiver.state();
expect(BigInt(state.amount)).toBeGreaterThanOrEqual(BigInt(new BN(receiverAmount).add(new BN(parseNearAmount('0.9'))).toString()));
});


});

0 comments on commit e07d1ca

Please sign in to comment.