Skip to content

Commit

Permalink
Merge pull request #661 from 0xs34n/0.12.0/remove-pending-transaction
Browse files Browse the repository at this point in the history
0.12.0/remove pending transaction
  • Loading branch information
tabaktoni committed Jun 29, 2023
2 parents 4b2fa60 + 8908a90 commit 35cb8a1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 68 deletions.
14 changes: 7 additions & 7 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,15 @@ describe('deploy and test Wallet', () => {
// const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
const estimatedFeeBulk = await account.estimateFeeBulk([
{
type: 'INVOKE_FUNCTION',
type: TransactionType.INVOKE,
payload: {
contractAddress: erc20Address,
entrypoint: 'transfer',
calldata: [erc20.address, '10', '0'],
},
},
{
type: 'INVOKE_FUNCTION',
type: TransactionType.INVOKE,
payload: {
contractAddress: erc20Address,
entrypoint: 'transfer',
Expand All @@ -679,7 +679,7 @@ describe('deploy and test Wallet', () => {

const res = await newAccount.estimateFeeBulk([
{
type: 'DEPLOY_ACCOUNT',
type: TransactionType.DEPLOY_ACCOUNT,
payload: {
classHash: accountClassHash,
constructorCalldata: { publicKey: starkKeyPub },
Expand All @@ -688,7 +688,7 @@ describe('deploy and test Wallet', () => {
},
},
{
type: 'INVOKE_FUNCTION',
type: TransactionType.INVOKE,
payload: [
{
contractAddress: erc20Address,
Expand Down Expand Up @@ -719,21 +719,21 @@ describe('deploy and test Wallet', () => {
}, */
{
// Cairo 0
type: 'DECLARE',
type: TransactionType.DECLARE,
payload: {
contract: compiledErc20,
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
},
},
{
type: 'DEPLOY',
type: TransactionType.DEPLOY,
payload: {
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
constructorCalldata: ['Token', 'ERC20', account.address],
},
},
{
type: 'INVOKE_FUNCTION',
type: TransactionType.INVOKE,
payload: [
{
contractAddress: erc20Address,
Expand Down
3 changes: 1 addition & 2 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ export class RpcProvider implements ProviderInterface {
const successStates = options?.successStates ?? [
TransactionStatus.ACCEPTED_ON_L1,
TransactionStatus.ACCEPTED_ON_L2,
TransactionStatus.PENDING,
];

while (!onchain) {
Expand All @@ -454,7 +453,7 @@ export class RpcProvider implements ProviderInterface {
txReceipt = await this.getTransactionReceipt(txHash);

if (!('status' in txReceipt)) {
const error = new Error('pending transaction');
const error = new Error('transaction status');
throw error;
}

Expand Down
1 change: 0 additions & 1 deletion src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ export class SequencerProvider implements ProviderInterface {
const successStates = options?.successStates ?? [
TransactionStatus.ACCEPTED_ON_L1,
TransactionStatus.ACCEPTED_ON_L2,
TransactionStatus.PENDING,
];

while (!onchain) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/api/openrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SIGNATURE = Array<FELT>;
type BLOCK_NUMBER = number;
type BLOCK_HASH = FELT;
type TXN_HASH = FELT;
type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
type TXN_STATUS = 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
export type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER';
type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
enum BLOCK_TAG {
Expand Down
23 changes: 12 additions & 11 deletions src/types/api/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {
BigNumberish,
BlockIdentifier,
BlockNumber,
BlockStatus,
ByteCode,
CairoAssembly,
CompiledContract,
ContractClass,
EntryPointType,
RawCalldata,
Status,
TransactionStatus,
TransactionType,
} from '../lib';

export type GetTransactionStatusResponse = {
Expand Down Expand Up @@ -80,7 +81,7 @@ export namespace Sequencer {
};

export type DeclareTransaction = {
type: 'DECLARE';
type: TransactionType.DECLARE;
sender_address: string;
contract_class: ContractClass;
signature?: string[];
Expand All @@ -91,15 +92,15 @@ export namespace Sequencer {
};

export type DeployTransaction = {
type: 'DEPLOY';
type: TransactionType.DEPLOY;
contract_definition: ContractClass;
contract_address_salt: BigNumberish;
constructor_calldata: string[];
nonce?: BigNumberish;
};

export type DeployAccountTransaction = {
type: 'DEPLOY_ACCOUNT';
type: TransactionType.DEPLOY_ACCOUNT;
class_hash: string;
contract_address_salt: BigNumberish;
constructor_calldata: string[];
Expand All @@ -110,7 +111,7 @@ export namespace Sequencer {
};

export type InvokeFunctionTransaction = {
type: 'INVOKE_FUNCTION';
type: TransactionType.INVOKE;
sender_address: string;
signature?: string[];
entry_point_type?: EntryPointType.EXTERNAL; // TODO: check this
Expand Down Expand Up @@ -149,15 +150,15 @@ export namespace Sequencer {
| InvokeFunctionTransactionResponse;

export type SuccessfulTransactionResponse = {
status: Status;
status: TransactionStatus;
transaction: TransactionResponse;
block_hash: string;
block_number: BlockNumber;
transaction_index: number;
};

export type FailedTransactionResponse = {
status: 'REJECTED';
status: TransactionStatus.REJECTED;
transaction_failure_reason: {
code: string;
error_message: string;
Expand All @@ -172,7 +173,7 @@ export namespace Sequencer {
| FailedTransactionReceiptResponse;

export type SuccessfulTransactionReceiptResponse = {
status: Status;
status: TransactionStatus;
transaction_hash: string;
transaction_index: number;
block_hash: string;
Expand All @@ -184,7 +185,7 @@ export namespace Sequencer {
};

export type FailedTransactionReceiptResponse = {
status: 'REJECTED';
status: TransactionStatus.REJECTED;
transaction_failure_reason: {
code: string;
error_message: string;
Expand Down Expand Up @@ -212,12 +213,12 @@ export namespace Sequencer {
from_address: string;
}[];
block_number: BlockNumber;
status: Status;
status: TransactionStatus;
transaction_index: number;
};
};
parent_block_hash: string;
status: Status;
status: BlockStatus;
gas_price: string;
sequencer_address: string;
starknet_version: string;
Expand Down
76 changes: 33 additions & 43 deletions src/types/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ export type UniversalDeployerContractPayload = {
constructorCalldata?: RawArgs;
};

/**
* @deprecated deprecated due to no direct deploy, unused - can be removed
*/
export type DeployContractPayload = {
contract: CompiledContract | string;
constructorCalldata?: RawCalldata;
addressSalt?: string;
};

export type DeployAccountContractPayload = {
classHash: string;
constructorCalldata?: RawArgs;
Expand Down Expand Up @@ -129,22 +120,45 @@ export type InvocationsDetailsWithNonce = InvocationsDetails & {
nonce: BigNumberish;
};

export enum TransactionType {
DECLARE = 'DECLARE',
DEPLOY = 'DEPLOY',
DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
INVOKE = 'INVOKE_FUNCTION',
}

export enum TransactionStatus {
NOT_RECEIVED = 'NOT_RECEIVED',
RECEIVED = 'RECEIVED',
PENDING = 'PENDING',
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
REJECTED = 'REJECTED',
}

export enum BlockStatus {
PENDING = 'PENDING',
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
REJECTED = 'REJECTED',
}

export type BlockTag = 'pending' | 'latest';
export type BlockNumber = BlockTag | null | number;

/**
* hex string and BN are detected as block hashes
* decimal string and number are detected as block numbers
* null appends nothing to the request url
*/
export type BlockIdentifier = BlockNumber | BigNumberish;

/**
* items used by AccountInvocations
*/
export type AccountInvocationItem = (
| ({ type: 'DECLARE' } & DeclareContractTransaction)
| ({ type: 'DEPLOY_ACCOUNT' } & DeployAccountContractTransaction)
| ({ type: 'INVOKE_FUNCTION' } & Invocation)
| ({ type: TransactionType.DECLARE } & DeclareContractTransaction)
| ({ type: TransactionType.DEPLOY_ACCOUNT } & DeployAccountContractTransaction)
| ({ type: TransactionType.INVOKE } & Invocation)
) &
InvocationsDetailsWithNonce;

Expand All @@ -157,40 +171,16 @@ export type AccountInvocations = AccountInvocationItem[];
* Invocations array user provide to bulk method (simulate)
*/
export type Invocations = Array<
| ({ type: 'DECLARE' } & OptionalPayload<DeclareContractPayload>)
| ({ type: 'DEPLOY' } & OptionalPayload<AllowArray<UniversalDeployerContractPayload>>)
| ({ type: 'DEPLOY_ACCOUNT' } & OptionalPayload<DeployAccountContractPayload>)
| ({ type: 'INVOKE_FUNCTION' } & OptionalPayload<AllowArray<Call>>)
| ({ type: TransactionType.DECLARE } & OptionalPayload<DeclareContractPayload>)
| ({ type: TransactionType.DEPLOY } & OptionalPayload<
AllowArray<UniversalDeployerContractPayload>
>)
| ({ type: TransactionType.DEPLOY_ACCOUNT } & OptionalPayload<DeployAccountContractPayload>)
| ({ type: TransactionType.INVOKE } & OptionalPayload<AllowArray<Call>>)
>;

export type Status =
| 'NOT_RECEIVED'
| 'RECEIVED'
| 'PENDING'
| 'ACCEPTED_ON_L2'
| 'ACCEPTED_ON_L1'
| 'REJECTED';

export enum TransactionType {
INVOKE = 'INVOKE_FUNCTION',
DECLARE = 'DECLARE',
DEPLOY = 'DEPLOY',
DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
}

export type Tupled = { element: any; type: string };

export type BlockTag = 'pending' | 'latest';
export type BlockNumber = BlockTag | null | number;
// hex string and BN are detected as block hashes
// decimal string and number are detected as block numbers
// null appends nothing to the request url
export type BlockIdentifier = BlockNumber | BigNumberish;

export type Struct = {
type: 'struct';
[k: string]: BigNumberish;
};
export type Args = {
[inputName: string]: BigNumberish | BigNumberish[] | ParsedStruct | ParsedStruct[];
};
Expand Down
7 changes: 4 additions & 3 deletions src/types/provider/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RPC } from '../api/rpc';
import { Sequencer } from '../api/sequencer';
import {
AllowArray,
BlockStatus,
ByteCode,
Call,
CompiledSierra,
Expand All @@ -15,7 +16,7 @@ import {
LegacyContractClass,
RawCalldata,
Signature,
Status,
TransactionStatus,
TransactionType,
UniversalDeployerContractPayload,
} from '../lib';
Expand All @@ -26,7 +27,7 @@ export interface GetBlockResponse {
block_number: number;
new_root: string;
parent_hash: string;
status: Status;
status: BlockStatus;
transactions: Array<string>;
gas_price?: string;
sequencer_address?: string;
Expand Down Expand Up @@ -72,7 +73,7 @@ export type GetTransactionReceiptResponse =

export interface CommonTransactionReceiptResponse {
transaction_hash: string;
status?: Status;
status?: `${TransactionStatus}`;
actual_fee?: string;
status_data?: string;
}
Expand Down

0 comments on commit 35cb8a1

Please sign in to comment.