@cryptorubic/web3 1.1.0-alpha-stellar.50 → 1.1.0-alpha-stellar.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/adapter/adapters/adapter-stellar/signer/stellar-adapter-signer.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-stellar/signer/stellar-adapter-signer.js +17 -4
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.d.ts +2 -2
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.js +16 -8
- package/src/lib/errors/blockchain/inactive-account.error.d.ts +4 -0
- package/src/lib/errors/blockchain/inactive-account.error.js +11 -0
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { StellarClient } from '../models/stellar-client';
|
|
|
4
4
|
import { StellarSendTxParams } from '../models/stellar-send-tx-params';
|
|
5
5
|
import { StellarWallet } from '../models/stellar-wallet';
|
|
6
6
|
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
7
|
+
import { xdr } from '@stellar/stellar-sdk';
|
|
7
8
|
export declare class StellarAdapterSigner extends AbstractAdapterSigner<StellarWallet, StellarSendTxParams, string> {
|
|
8
9
|
private readonly publicRef;
|
|
9
10
|
get publicClient(): StellarClient;
|
|
@@ -13,4 +14,5 @@ export declare class StellarAdapterSigner extends AbstractAdapterSigner<StellarW
|
|
|
13
14
|
write<T>(): Promise<T>;
|
|
14
15
|
getBlockchainName(): Promise<BlockchainName>;
|
|
15
16
|
sendTransaction(params: StellarSendTxParams): Promise<string>;
|
|
17
|
+
parseTxError(txResult: xdr.TransactionResult): void;
|
|
16
18
|
}
|
|
@@ -43,18 +43,31 @@ class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSign
|
|
|
43
43
|
address: this.walletAddress
|
|
44
44
|
});
|
|
45
45
|
const resp = await this.publicClient.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const txStatus = await this.publicClient.pollTransaction(resp.hash);
|
|
47
|
+
if (txStatus.status === 'FAILED') {
|
|
48
|
+
this.parseTxError(txStatus.resultXdr);
|
|
48
49
|
}
|
|
49
50
|
if (params.txOptions.onTransactionHash) {
|
|
50
|
-
params.txOptions.onTransactionHash?.(
|
|
51
|
+
params.txOptions.onTransactionHash?.(txStatus.txHash);
|
|
51
52
|
}
|
|
52
|
-
return
|
|
53
|
+
return txStatus.txHash;
|
|
53
54
|
}
|
|
54
55
|
catch (err) {
|
|
55
56
|
console.error('Send transaction error', err);
|
|
56
57
|
throw err;
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
parseTxError(txResult) {
|
|
61
|
+
const failedTxCode = txResult.result().switch().name;
|
|
62
|
+
if (failedTxCode === 'txInsufficientBalance') {
|
|
63
|
+
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
64
|
+
}
|
|
65
|
+
const failedOperation = txResult.result().results()[0];
|
|
66
|
+
const failedOperationCode = failedOperation.tr().value().switch().name;
|
|
67
|
+
if (failedOperationCode === 'changeTrustLowReserve') {
|
|
68
|
+
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
69
|
+
}
|
|
70
|
+
throw new Error(failedOperationCode);
|
|
71
|
+
}
|
|
59
72
|
}
|
|
60
73
|
exports.StellarAdapterSigner = StellarAdapterSigner;
|
|
@@ -3,7 +3,7 @@ import { AbstractAdapter } from '../common/abstract-adapter';
|
|
|
3
3
|
import { StellarClient } from './models/stellar-client';
|
|
4
4
|
import { StellarWallet } from './models/stellar-wallet';
|
|
5
5
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
6
|
-
import { Horizon } from '@stellar/stellar-sdk';
|
|
6
|
+
import { Account, Horizon } from '@stellar/stellar-sdk';
|
|
7
7
|
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
8
8
|
import { StellarAdapterSigner } from './signer/stellar-adapter-signer';
|
|
9
9
|
import BigNumber from 'bignumber.js';
|
|
@@ -42,7 +42,7 @@ export declare class StellarAdapter extends AbstractAdapter<StellarClient, Stell
|
|
|
42
42
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
43
43
|
getMinWeiBalance(userAddress: string): Promise<BigNumber>;
|
|
44
44
|
getFeeFromTransaction(xdr: string): BigNumber;
|
|
45
|
-
|
|
45
|
+
getAccountInfo(walletAddress: string): Promise<Account>;
|
|
46
46
|
callContractMethod<T extends Web3PrimitiveType = string>(_contractAddress: string, _contractAbi: Abi | undefined, _methodName: string, _methodArguments?: {
|
|
47
47
|
value: string;
|
|
48
48
|
type: string;
|
|
@@ -10,7 +10,7 @@ const stellar_sdk_2 = require("@stellar/stellar-sdk");
|
|
|
10
10
|
const bignumber_js_1 = require("bignumber.js");
|
|
11
11
|
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
12
12
|
const fake_stellar_wallet_1 = require("./constants/fake-stellar-wallet");
|
|
13
|
-
const
|
|
13
|
+
const inactive_account_error_1 = require("../../../errors/blockchain/inactive-account.error");
|
|
14
14
|
class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
15
15
|
constructor(rpc, httpClient, logger, clientParams) {
|
|
16
16
|
super(core_1.BLOCKCHAIN_NAME.STELLAR, logger);
|
|
@@ -132,9 +132,12 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
132
132
|
address: this.signer.walletAddress
|
|
133
133
|
});
|
|
134
134
|
const resp = await this.public.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
135
|
+
if (resp.status === 'ERROR' && resp.errorResult) {
|
|
136
|
+
this.signer.parseTxError(resp.errorResult);
|
|
137
|
+
}
|
|
135
138
|
const resStatus = await this.public.pollTransaction(resp.hash);
|
|
136
139
|
if (resStatus.status === 'FAILED') {
|
|
137
|
-
this.parseTxError(resStatus.resultXdr);
|
|
140
|
+
this.signer.parseTxError(resStatus.resultXdr);
|
|
138
141
|
}
|
|
139
142
|
return resStatus.txHash;
|
|
140
143
|
}
|
|
@@ -144,7 +147,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
async encodeTrustline(tokenAddress, walletAddress) {
|
|
147
|
-
const account = await this.
|
|
150
|
+
const account = await this.getAccountInfo(walletAddress);
|
|
148
151
|
const tx = new stellar_sdk_1.TransactionBuilder(account, {
|
|
149
152
|
fee: stellar_sdk_1.BASE_FEE,
|
|
150
153
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
@@ -226,11 +229,16 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
226
229
|
const parsedTranssaction = stellar_sdk_1.TransactionBuilder.fromXDR(xdr, stellar_sdk_1.Networks.PUBLIC);
|
|
227
230
|
return new bignumber_js_1.default(parsedTranssaction.fee);
|
|
228
231
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
async getAccountInfo(walletAddress) {
|
|
233
|
+
try {
|
|
234
|
+
const account = await this.public.getAccount(walletAddress);
|
|
235
|
+
return account;
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
if (err.message?.includes('Account not found')) {
|
|
239
|
+
throw new inactive_account_error_1.InactiveAccountError();
|
|
240
|
+
}
|
|
241
|
+
throw err;
|
|
234
242
|
}
|
|
235
243
|
}
|
|
236
244
|
async callContractMethod(_contractAddress, _contractAbi = [], _methodName, _methodArguments = [], _options) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InactiveAccountError = void 0;
|
|
4
|
+
const rubic_sdk_error_1 = require("../rubic-sdk.error");
|
|
5
|
+
class InactiveAccountError extends rubic_sdk_error_1.RubicSdkError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Account is not activated');
|
|
8
|
+
Object.setPrototypeOf(this, InactiveAccountError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.InactiveAccountError = InactiveAccountError;
|