Skip to content

Commit

Permalink
feat: implement RPC v0.7.0-rc2 specification
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Mar 7, 2024
1 parent 9635a26 commit de32936
Show file tree
Hide file tree
Showing 19 changed files with 2,082 additions and 75 deletions.
3 changes: 2 additions & 1 deletion __tests__/utils/stark.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CallData, RawArgs, UniversalDetails, json, stark } from '../../src';
import { EDataAvailabilityMode, FeeEstimate } from '../../src/types/api';
import { EDataAvailabilityMode } from '../../src/types/api';
import { FeeEstimate } from '../../src/types/provider';
import { toBigInt, toHex } from '../../src/utils/num';
import { compiledOpenZeppelinAccount } from '../config/fixtures';

Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/transactionHash.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { constants, hash, shortString, types, v2hash, v3hash } from '../../src';
import { ResourceBounds } from '../../src/types/api/rpcspec_0_6';
import { ResourceBounds } from '../../src/types/api';

describe('TxV2 Hash Tests', () => {
describe('calculateTransactionHashCommon()', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/channel/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './rpc_0_6';
export * as RPC06 from './rpc_0_6';
export * as RPC07 from './rpc_0_7';
export * from './rpc_0_7';
21 changes: 10 additions & 11 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import {
DeployAccountContractTransaction,
Invocation,
InvocationsDetailsWithNonce,
RPC,
RpcProviderOptions,
TransactionType,
getEstimateFeeBulkOptions,
getSimulateTransactionOptions,
waitForTransactionOptions,
} from '../types';
import { ETransactionVersion } from '../types/api';
import { JRPC, RPCSPEC06 as RPC } from '../types/api';
import { CallData } from '../utils/calldata';
import { isSierra } from '../utils/contract';
import fetch from '../utils/fetchPonyfill';
Expand Down Expand Up @@ -72,7 +71,7 @@ export class RpcChannel {
}

public fetch(method: string, params?: object, id: string | number = 0) {
const rpcRequestBody: RPC.JRPC.RequestBody = {
const rpcRequestBody: JRPC.RequestBody = {
id,
jsonrpc: '2.0',
method,
Expand All @@ -85,7 +84,7 @@ export class RpcChannel {
});
}

protected errorHandler(method: string, params: any, rpcError?: RPC.JRPC.Error, otherError?: any) {
protected errorHandler(method: string, params: any, rpcError?: JRPC.Error, otherError?: any) {
if (rpcError) {
const { code, message, data } = rpcError;
throw new LibraryError(
Expand Down Expand Up @@ -398,7 +397,7 @@ export class RpcChannel {
calldata: CallData.toHex(functionInvocation.calldata),
type: RPC.ETransactionType.INVOKE,
max_fee: toHex(details.maxFee || 0),
version: ETransactionVersion.V1,
version: RPC.ETransactionVersion.V1,
signature: signatureToHexArray(functionInvocation.signature),
nonce: toHex(details.nonce),
},
Expand All @@ -410,7 +409,7 @@ export class RpcChannel {
type: RPC.ETransactionType.INVOKE,
sender_address: functionInvocation.contractAddress,
calldata: CallData.toHex(functionInvocation.calldata),
version: ETransactionVersion.V3,
version: RPC.ETransactionVersion.V3,
signature: signatureToHexArray(functionInvocation.signature),
nonce: toHex(details.nonce),
resource_bounds: details.resourceBounds,
Expand Down Expand Up @@ -441,7 +440,7 @@ export class RpcChannel {
entry_points_by_type: contract.entry_points_by_type,
abi: contract.abi,
},
version: ETransactionVersion.V1,
version: RPC.ETransactionVersion.V1,
max_fee: toHex(details.maxFee || 0),
signature: signatureToHexArray(signature),
sender_address: senderAddress,
Expand All @@ -460,7 +459,7 @@ export class RpcChannel {
abi: contract.abi,
},
compiled_class_hash: compiledClassHash || '',
version: ETransactionVersion.V2,
version: RPC.ETransactionVersion.V2,
max_fee: toHex(details.maxFee || 0),
signature: signatureToHexArray(signature),
sender_address: senderAddress,
Expand All @@ -474,7 +473,7 @@ export class RpcChannel {
type: RPC.ETransactionType.DECLARE,
sender_address: senderAddress,
compiled_class_hash: compiledClassHash || '',
version: ETransactionVersion.V3,
version: RPC.ETransactionVersion.V3,
signature: signatureToHexArray(signature),
nonce: toHex(details.nonce),
contract_class: {
Expand Down Expand Up @@ -512,7 +511,7 @@ export class RpcChannel {
contract_address_salt: toHex(addressSalt || 0),
type: RPC.ETransactionType.DEPLOY_ACCOUNT,
max_fee: toHex(details.maxFee || 0),
version: ETransactionVersion.V1,
version: RPC.ETransactionVersion.V1,
signature: signatureToHexArray(signature),
nonce: toHex(details.nonce),
},
Expand All @@ -522,7 +521,7 @@ export class RpcChannel {
promise = this.fetchEndpoint('starknet_addDeployAccountTransaction', {
deploy_account_transaction: {
type: RPC.ETransactionType.DEPLOY_ACCOUNT,
version: ETransactionVersion.V3,
version: RPC.ETransactionVersion.V3,
signature: signatureToHexArray(signature),
nonce: toHex(details.nonce),
contract_address_salt: toHex(addressSalt || 0),
Expand Down
Loading

0 comments on commit de32936

Please sign in to comment.