Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starknetjs rpc implementation #3

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ on:
pull_request:
branches: '*'


jobs:
quality:
name: Quality test
Expand All @@ -39,17 +38,17 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [quality]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Run Release on Node lts/*
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npx semantic-release --debug ${{ inputs.debug }} --dry-run ${{ inputs.dry-run }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Run Release on Node lts/*
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npx semantic-release --debug ${{ inputs.debug }} --dry-run ${{ inputs.dry-run }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknet-types",
"version": "0.7.1",
"version": "0.7.2",
"description": "Shared TypeScript definitions for Starknet projects",
"homepage": "https://github.com/starknet-io/types-js",
"keywords": [
Expand Down
100 changes: 100 additions & 0 deletions src/api/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* TypeScript Representation of Cairo1 v2+ Starknet Contract ABI
*
* starknet_metadata.json - tags/v0.5.0
*
* 'starknet-specs' (OpenRpc protocol types)
* https://github.com/starkware-libs/starknet-specs
*/

export type ABI = Array<
FUNCTION | CONSTRUCTOR | L1_HANDLER | EVENT | STRUCT | ENUM | INTERFACE | IMPL
>;

type FUNCTION = {
type: 'function';
name: string;
inputs: Array<{
name: string;
type: string;
}>;
outputs?: Array<{
type: string;
}>;
state_mutability: 'view' | 'external';
};

type CONSTRUCTOR = {
type: 'constructor';
name: 'constructor';
inputs: Array<{
name: string;
type: string;
}>;
};

type L1_HANDLER = {
type: 'l1_handler';
name: string;
inputs: Array<{
name: string;
type: string;
}>;
outputs?: Array<{
type: string;
}>;
state_mutability: 'view' | 'external';
};

type EVENT = {
type: 'event';
name: string;
} & (ENUM_EVENT | STRUCT_EVENT);

type STRUCT_EVENT = {
kind: 'struct';
members: Array<EVENT_FIELD>;
};

type ENUM_EVENT = {
kind: 'enum';
variants: Array<EVENT_FIELD>;
};

type STRUCT = {
type: 'struct';
name: string;
members: Array<{
name: string;
type: string;
}>;
};

type ENUM = {
type: 'enum';
name: string;
variants: Array<{
name: string;
type: string;
}>;
};

type INTERFACE = {
type: 'interface';
name: string;
items: Array<FUNCTION>;
};

type IMPL = {
type: 'impl';
name: string;
interface_name: string;
};

export type EVENT_KIND = 'struct' | 'enum';

type EVENT_FIELD = {
name: string;
type: string;
kind: 'key' | 'data' | 'nested';
};
156 changes: 156 additions & 0 deletions src/api/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
export interface FAILED_TO_RECEIVE_TXN {
code: 1;
message: 'Failed to write transaction';
}

export interface NO_TRACE_AVAILABLE {
code: 10;
message: 'No trace available for transaction';
data: {
status: 'RECEIVED' | 'REJECTED';
};
}

export interface CONTRACT_NOT_FOUND {
code: 20;
message: 'Contract not found';
}

export interface INVALID_MESSAGE_SELECTOR {
code: 21;
message: 'Invalid message selector';
}

export interface INVALID_CALL_DATA {
code: 22;
message: 'Invalid call data';
}

export interface BLOCK_NOT_FOUND {
code: 24;
message: 'Block not found';
}

export interface INVALID_BLOCK_HASH {
code: 26;
message: 'Invalid block hash';
}

export interface INVALID_TXN_INDEX {
code: 27;
message: 'Invalid transaction index in a block';
}

export interface CLASS_HASH_NOT_FOUND {
code: 28;
message: 'Class hash not found';
}

export interface TXN_HASH_NOT_FOUND {
code: 29;
message: 'Transaction hash not found';
}

export interface PAGE_SIZE_TOO_BIG {
code: 31;
message: 'Requested page size is too big';
}

export interface NO_BLOCKS {
code: 32;
message: 'There are no blocks';
}

export interface INVALID_CONTINUATION_TOKEN {
code: 33;
message: 'The supplied continuation token is invalid or unknown';
}

export interface TOO_MANY_KEYS_IN_FILTER {
code: 34;
message: 'Too many keys provided in a filter';
}

export interface CONTRACT_ERROR {
code: 40;
message: 'Contract error';
data: {
revert_error: string;
};
}

export interface TRANSACTION_EXECUTION_ERROR {
code: 41;
message: 'Transaction execution error';
data: {
transaction_index: number;
execution_error: string;
};
}

export interface CLASS_ALREADY_DECLARED {
code: 51;
message: 'Class already declared';
}

export interface INVALID_TRANSACTION_NONCE {
code: 52;
message: 'Invalid transaction nonce';
}

export interface INSUFFICIENT_MAX_FEE {
code: 53;
message: 'Max fee is smaller than the minimal transaction cost (validation plus fee transfer)';
}

export interface INSUFFICIENT_ACCOUNT_BALANCE {
code: 54;
message: "Account balance is smaller than the transaction's max_fee";
}

export interface VALIDATION_FAILURE {
code: 55;
message: 'Account validation failed';
data: string;
}

export interface COMPILATION_FAILED {
code: 56;
message: 'Compilation failed';
}

export interface CONTRACT_CLASS_SIZE_IS_TOO_LARGE {
code: 57;
message: 'Contract class size it too large';
}

export interface NON_ACCOUNT {
code: 58;
message: 'Sender address in not an account contract';
}

export interface DUPLICATE_TX {
code: 59;
message: 'A transaction with the same hash already exists in the mempool';
}

export interface COMPILED_CLASS_HASH_MISMATCH {
code: 60;
message: 'the compiled class hash did not match the one supplied in the transaction';
}

export interface UNSUPPORTED_TX_VERSION {
code: 61;
message: 'the transaction version is not supported';
}

export interface UNSUPPORTED_CONTRACT_CLASS_VERSION {
code: 62;
message: 'the contract class version is not supported';
}

export interface UNEXPECTED_ERROR {
code: 63;
message: 'An unexpected error occurred';
data: string;
}
5 changes: 5 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type { Methods } from './methods.js';
export type { ABI } from './contract.js';
export * as Errors from './errors.js';
export * as SPEC from './components.js';
export * from './nonspec.js';
Loading