Skip to content

Commit 7ecb069

Browse files
committed
feat(provider): fix and clean provider response and response parser, removed seqeuncer api
1 parent 2d0c322 commit 7ecb069

File tree

13 files changed

+101
-775
lines changed

13 files changed

+101
-775
lines changed

__tests__/contract.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {
22
BigNumberish,
33
Contract,
44
ContractFactory,
5+
GetTransactionReceiptResponse,
56
ParsedEvents,
67
RawArgs,
7-
SuccessfulTransactionReceiptResponse,
88
json,
99
stark,
1010
} from '../src';
@@ -720,7 +720,7 @@ describe('Complex interaction', () => {
720720
test('invoke compiled data', async () => {
721721
const result = await erc20Echo20Contract.iecho(CallData.compile(request));
722722
const transaction = await provider.waitForTransaction(result.transaction_hash);
723-
expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
723+
expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined();
724724
});
725725

726726
// skip on live for performance
@@ -730,19 +730,19 @@ describe('Complex interaction', () => {
730730

731731
const result = await erc20Echo20Contract.iecho(calldata);
732732
const transaction = await provider.waitForTransaction(result.transaction_hash);
733-
expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
733+
expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined();
734734

735735
const result1 = await erc20Echo20Contract.iecho(...args);
736736
const transaction1 = await provider.waitForTransaction(result1.transaction_hash);
737-
expect((transaction1 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
737+
expect((transaction1 as GetTransactionReceiptResponse).execution_status).toBeDefined();
738738

739739
const result2 = await erc20Echo20Contract.invoke('iecho', calldata);
740740
const transaction2 = await provider.waitForTransaction(result2.transaction_hash);
741-
expect((transaction2 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
741+
expect((transaction2 as GetTransactionReceiptResponse).execution_status).toBeDefined();
742742

743743
const result3 = await erc20Echo20Contract.invoke('iecho', args);
744744
const transaction3 = await provider.waitForTransaction(result3.transaction_hash);
745-
expect((transaction3 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
745+
expect((transaction3 as GetTransactionReceiptResponse).execution_status).toBeDefined();
746746
});
747747

748748
describe('speedup live tests', () => {
@@ -795,9 +795,7 @@ describe('Complex interaction', () => {
795795
{ formatResponse }
796796
);
797797
const transaction = await provider.waitForTransaction(result.transaction_hash);
798-
expect(
799-
(transaction as SuccessfulTransactionReceiptResponse).execution_status
800-
).toBeDefined();
798+
expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined();
801799
});
802800
});
803801

__tests__/defaultProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe('defaultProvider', () => {
181181
}),
182182
})
183183
.then((res) => {
184-
expect(Array.isArray(res.result)).toBe(true);
184+
expect(Array.isArray(res)).toBe(true);
185185
})
186186
).resolves.not.toThrow();
187187
});

src/contract/default.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,14 @@ export class Contract implements ContractInterface {
248248
},
249249
blockIdentifier
250250
)
251-
.then((x) => {
251+
.then((it) => {
252252
if (!parseResponse) {
253-
return x.result;
253+
return it;
254254
}
255255
if (formatResponse) {
256-
return this.callData.format(method, x.result, formatResponse);
256+
return this.callData.format(method, it, formatResponse);
257257
}
258-
return this.callData.parse(method, x.result);
258+
return this.callData.parse(method, it);
259259
});
260260
}
261261

src/provider/extensions/starknetId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class StarknetId {
3838
address,
3939
}),
4040
});
41-
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
41+
const decimalDomain = hexDomain.map((element) => BigInt(element)).slice(1);
4242

4343
const stringDomain = useDecoded(decimalDomain);
4444

@@ -72,7 +72,7 @@ export class StarknetId {
7272
}),
7373
});
7474

75-
return addressData.result[0];
75+
return addressData[0];
7676
} catch {
7777
throw Error('Could not get address from stark name');
7878
}

src/provider/rpc.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ export class RpcProvider implements ProviderInterface {
119119
}
120120

121121
public async getTransaction(txHash: BigNumberish) {
122-
return this.channel
123-
.getTransactionByHash(txHash)
124-
.then(this.responseParser.parseGetTransactionResponse);
122+
return this.channel.getTransactionByHash(txHash);
125123
}
126124

127125
public async getTransactionByHash(txHash: BigNumberish) {
@@ -161,7 +159,9 @@ export class RpcProvider implements ProviderInterface {
161159
options?: getSimulateTransactionOptions
162160
) {
163161
// can't be named simulateTransaction because of argument conflict with account
164-
return this.channel.simulateTransaction(invocations, options);
162+
return this.channel
163+
.simulateTransaction(invocations, options)
164+
.then(this.responseParser.parseSimulateTransactionResponse);
165165
}
166166

167167
public async waitForTransaction(txHash: BigNumberish, options?: waitForTransactionOptions) {
@@ -340,9 +340,8 @@ export class RpcProvider implements ProviderInterface {
340340
}
341341

342342
public async callContract(call: Call, blockIdentifier?: BlockIdentifier) {
343-
return this.channel
344-
.callContract(call, blockIdentifier)
345-
.then(this.responseParser.parseCallContractResponse);
343+
return this.channel.callContract(call, blockIdentifier);
344+
// .then(this.responseParser.parseCallContractResponse);
346345
}
347346

348347
/**

src/types/account.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { EDataAvailabilityMode, ETransactionVersion, ResourceBounds } from './api';
2-
import { BigNumberish, BlockIdentifier, V3TransactionDetails } from './lib';
2+
import {
3+
AllowArray,
4+
BigNumberish,
5+
BlockIdentifier,
6+
Call,
7+
DeclareContractPayload,
8+
DeployAccountContractPayload,
9+
TransactionType,
10+
UniversalDeployerContractPayload,
11+
V3TransactionDetails,
12+
} from './lib';
313
import { DeclareTransactionReceiptResponse, EstimateFeeResponse } from './provider';
414

515
export interface EstimateFee extends EstimateFeeResponse {}
@@ -69,3 +79,21 @@ export enum SIMULATION_FLAG {
6979
SKIP_VALIDATE = 'SKIP_VALIDATE',
7080
SKIP_EXECUTE = 'SKIP_EXECUTE',
7181
}
82+
83+
export type EstimateFeeAction =
84+
| {
85+
type: TransactionType.INVOKE;
86+
payload: AllowArray<Call>;
87+
}
88+
| {
89+
type: TransactionType.DECLARE;
90+
payload: DeclareContractPayload;
91+
}
92+
| {
93+
type: TransactionType.DEPLOY_ACCOUNT;
94+
payload: DeployAccountContractPayload;
95+
}
96+
| {
97+
type: TransactionType.DEPLOY;
98+
payload: UniversalDeployerContractPayload;
99+
};

src/types/api/rpcspec_0_6/methods.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import {
1111
FELT,
1212
FUNCTION_CALL,
1313
MSG_FROM_L1,
14-
PENDING_STATE_UPDATE,
1514
RESULT_PAGE_REQUEST,
1615
SIMULATION_FLAG,
1716
SIMULATION_FLAG_FOR_ESTIMATE_FEE,
18-
STATE_UPDATE,
1917
STORAGE_KEY,
2018
TXN_HASH,
2119
} from './components';
@@ -33,6 +31,7 @@ import {
3331
InvokedTransaction,
3432
Nonce,
3533
SimulateTransactionResponse,
34+
StateUpdate,
3635
Syncing,
3736
TransactionReceipt,
3837
TransactionStatus,
@@ -72,7 +71,7 @@ type ReadMethods = {
7271
params: {
7372
block_id: BLOCK_ID;
7473
};
75-
result: STATE_UPDATE | PENDING_STATE_UPDATE;
74+
result: StateUpdate;
7675
errors: Errors.BLOCK_NOT_FOUND;
7776
};
7877

src/types/api/rpcspec_0_6/nonspec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ import {
4242
// response starknet_getClass
4343
export type ContractClass = CONTRACT_CLASS | DEPRECATED_CONTRACT_CLASS;
4444
// response starknet_simulateTransactions
45-
export type SimulateTransactionResponse = {
45+
export type SimulateTransaction = {
4646
transaction_trace: TRANSACTION_TRACE;
4747
fee_estimation: FEE_ESTIMATE;
48-
}[];
48+
};
49+
export type SimulateTransactionResponse = SimulateTransaction[];
4950
// response starknet_estimateFee
5051
export type FeeEstimate = FEE_ESTIMATE;
5152
// response starknet_getTransactionByHash, starknet_getTransactionByBlockIdAndIndex
@@ -79,6 +80,8 @@ export type TransactionHash = TXN_HASH;
7980
export type TransactionTrace = TRANSACTION_TRACE;
8081
export type BlockHash = BLOCK_HASH;
8182
export type TransactionReceipt = TXN_RECEIPT | PENDING_TXN_RECEIPT;
83+
export type Receipt = TXN_RECEIPT;
84+
export type PendingReceipt = PENDING_TXN_RECEIPT;
8285
export type EventFilter = EVENT_FILTER & RESULT_PAGE_REQUEST;
8386
export type SimulationFlags = Array<SIMULATION_FLAG>;
8487
export type L1Message = MSG_FROM_L1;

0 commit comments

Comments
 (0)