Skip to content

Commit

Permalink
feat: minimal changes api
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Mar 6, 2023
1 parent 50a2c29 commit 7cec344
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
12 changes: 8 additions & 4 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export abstract class ProviderInterface {
public abstract getEstimateFee(
invocation: Invocation,
details: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier
blockIdentifier: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;

/**
Expand All @@ -228,7 +229,8 @@ export abstract class ProviderInterface {
public abstract getInvokeEstimateFee(
invocation: Invocation,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;

/**
Expand All @@ -248,7 +250,8 @@ export abstract class ProviderInterface {
public abstract getDeclareEstimateFee(
transaction: DeclareContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;

/**
Expand All @@ -269,7 +272,8 @@ export abstract class ProviderInterface {
public abstract getDeployAccountEstimateFee(
transaction: DeployAccountContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;

/**
Expand Down
28 changes: 16 additions & 12 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export class SequencerProvider implements ProviderInterface {
): Promise<InvokeFunctionResponse> {
return this.fetchEndpoint('add_transaction', undefined, {
type: TransactionType.INVOKE,
contract_address: functionInvocation.contractAddress,
sender_address: functionInvocation.contractAddress,
calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
signature: signatureToDecimalArray(functionInvocation.signature),
nonce: toHex(details.nonce),
Expand Down Expand Up @@ -402,22 +402,24 @@ export class SequencerProvider implements ProviderInterface {
public async getEstimateFee(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = this.blockIdentifier
blockIdentifier: BlockIdentifier = this.blockIdentifier,
skipValidate: boolean = false
): Promise<EstimateFeeResponse> {
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate);
}

public async getInvokeEstimateFee(
invocation: Invocation,
invocationDetails: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = this.blockIdentifier
blockIdentifier: BlockIdentifier = this.blockIdentifier,
skipValidate: boolean = false
): Promise<EstimateFeeResponse> {
return this.fetchEndpoint(
'estimate_fee',
{ blockIdentifier },
{ blockIdentifier, skip_validate: skipValidate },
{
type: TransactionType.INVOKE,
contract_address: invocation.contractAddress,
sender_address: invocation.contractAddress,
calldata: invocation.calldata ?? [],
signature: signatureToDecimalArray(invocation.signature),
version: toHex(invocationDetails?.version || 1),
Expand All @@ -429,11 +431,12 @@ export class SequencerProvider implements ProviderInterface {
public async getDeclareEstimateFee(
{ senderAddress, contractDefinition, signature }: DeclareContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = this.blockIdentifier
blockIdentifier: BlockIdentifier = this.blockIdentifier,
skipValidate: boolean = false
): Promise<EstimateFeeResponse> {
return this.fetchEndpoint(
'estimate_fee',
{ blockIdentifier },
{ blockIdentifier, skip_validate: skipValidate },
{
type: TransactionType.DECLARE,
sender_address: senderAddress,
Expand All @@ -448,11 +451,12 @@ export class SequencerProvider implements ProviderInterface {
public async getDeployAccountEstimateFee(
{ classHash, addressSalt, constructorCalldata, signature }: DeployAccountContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier = this.blockIdentifier
blockIdentifier: BlockIdentifier = this.blockIdentifier,
skipValidate: boolean = false
): Promise<EstimateFeeResponse> {
return this.fetchEndpoint(
'estimate_fee',
{ blockIdentifier },
{ blockIdentifier, skip_validate: skipValidate },
{
type: TransactionType.DEPLOY_ACCOUNT,
class_hash: toHex(classHash),
Expand All @@ -474,7 +478,7 @@ export class SequencerProvider implements ProviderInterface {
if (invocation.type === 'INVOKE_FUNCTION') {
res = {
type: invocation.type,
contract_address: invocation.contractAddress,
sender_address: invocation.contractAddress,
calldata: invocation.calldata ?? [],
};
} else if (invocation.type === 'DECLARE') {
Expand Down Expand Up @@ -603,7 +607,7 @@ export class SequencerProvider implements ProviderInterface {
{ blockIdentifier },
{
type: 'INVOKE_FUNCTION',
contract_address: invocation.contractAddress,
sender_address: invocation.contractAddress,
calldata: invocation.calldata ?? [],
signature: signatureToDecimalArray(invocation.signature),
version: toHex(invocationDetails?.version || 1),
Expand Down
15 changes: 10 additions & 5 deletions src/types/api/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export namespace Sequencer {

export type InvokeFunctionTransaction = {
type: 'INVOKE_FUNCTION';
contract_address: string;
sender_address: string;
signature?: string[];
entry_point_type?: EntryPointType;
calldata?: RawCalldata;
Expand Down Expand Up @@ -221,10 +221,14 @@ export namespace Sequencer {
starknet_version: string;
};

export type CallContractTransaction = Omit<
InvokeFunctionTransaction,
'type' | 'entry_point_type' | 'nonce'
> & { entry_point_selector: string };
export type CallContractTransaction = {
contract_address: string;
signature?: string[];
calldata?: RawCalldata;
max_fee?: BigNumberish;
version?: BigNumberish;
entry_point_selector: string;
};

export type CallContractResponse = {
result: string[];
Expand Down Expand Up @@ -386,6 +390,7 @@ export namespace Sequencer {
estimate_fee: {
QUERY: {
blockIdentifier: BlockIdentifier;
skip_validate: boolean;
};
REQUEST: EstimateFeeRequest;
RESPONSE: EstimateFeeResponse;
Expand Down
3 changes: 2 additions & 1 deletion src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export interface CommonTransactionResponse {
}

export interface InvokeTransactionResponse extends CommonTransactionResponse {
contract_address?: string;
contract_address?: string; // TODO: Added for RPC comp, remove when rpc update to sender_address
sender_address?: string;
entry_point_selector?: string;
calldata: RawCalldata;
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/responseParser/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class RPCResponseParser
return {
calldata: res.calldata || [],
contract_address: res.contract_address,
sender_address: res.contract_address,
max_fee: res.max_fee,
nonce: res.nonce,
signature: res.signature || [],
Expand Down
2 changes: 0 additions & 2 deletions src/utils/responseParser/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class SequencerAPIResponseParser extends ResponseParser {
return {
...res,
calldata: 'calldata' in res.transaction ? (res.transaction.calldata as Array<string>) : [],
contract_address:
'contract_address' in res.transaction ? res.transaction.contract_address : undefined,
contract_class:
'contract_class' in res.transaction ? (res.transaction.contract_class as any) : undefined,
entry_point_selector:
Expand Down

0 comments on commit 7cec344

Please sign in to comment.