From 930a629bf6576616e5f66fafa0b394f1b6d68a84 Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 09:37:30 +0200 Subject: [PATCH 01/16] docs: delete --- docs/README.md | 222 ------------------------------------------------- 1 file changed, 222 deletions(-) delete mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index b0ccea8ef..000000000 --- a/docs/README.md +++ /dev/null @@ -1,222 +0,0 @@ -StarkNet.js Docs - -# StarkNet.js Docs - -## Table of contents - -### Functions - -- [addTransaction](README.md#addtransaction) -- [callContract](README.md#callcontract) -- [getBlock](README.md#getblock) -- [getCode](README.md#getcode) -- [getContractAddresses](README.md#getcontractaddresses) -- [getStorageAt](README.md#getstorageat) -- [getTransaction](README.md#gettransaction) -- [getTransactionStatus](README.md#gettransactionstatus) - -## Functions - -### addTransaction - -▸ **addTransaction**(`tx`): `Promise`<`object`\> - -Invoke a function on the starknet contract - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17) - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `tx` | `object` | transaction to be invoked (WIP) | - -#### Returns - -`Promise`<`object`\> - -a confirmation of invoking a function on the starknet contract - -#### Defined in - -[index.ts:156](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L156) - -___ - -### callContract - -▸ **callContract**(`invokeTx`, `blockId`): `Promise`<`object`\> - -Calls a function on the StarkNet contract. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25) - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `invokeTx` | `object` | transaction to be invoked (WIP) | -| `blockId` | `number` | | - -#### Returns - -`Promise`<`object`\> - -the result of the function on the smart contract. - -#### Defined in - -[index.ts:33](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L33) - -___ - -### getBlock - -▸ **getBlock**(`blockId`): `Promise`<`object`\> - -Gets the block information from a block ID. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `blockId` | `number` | - -#### Returns - -`Promise`<`object`\> - -the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions } - -#### Defined in - -[index.ts:52](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L52) - -___ - -### getCode - -▸ **getCode**(`contractAddress`, `blockId`): `Promise`<`object`\> - -Gets the code of the deployed contract. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `contractAddress` | `string` | -| `blockId` | `number` | - -#### Returns - -`Promise`<`object`\> - -ABI of compiled contract in JSON - -#### Defined in - -[index.ts:72](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L72) - -___ - -### getContractAddresses - -▸ **getContractAddresses**(): `Promise`<`object`\> - -Gets the smart contract address on the goerli testnet. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15) - -#### Returns - -`Promise`<`object`\> - -starknet smart contract address - -#### Defined in - -[index.ts:13](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L13) - -___ - -### getStorageAt - -▸ **getStorageAt**(`contractAddress`, `key`, `blockId`): `Promise`<`object`\> - -Gets the contract's storage variable at a specific key. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46) - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `contractAddress` | `string` | | -| `key` | `number` | from getStorageVarAddress('') (WIP) | -| `blockId` | `number` | | - -#### Returns - -`Promise`<`object`\> - -the value of the storage variable - -#### Defined in - -[index.ts:93](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L93) - -___ - -### getTransaction - -▸ **getTransaction**(`txId`): `Promise`<`object`\> - -Gets the transaction information from a tx id. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `txId` | `number` | - -#### Returns - -`Promise`<`object`\> - -the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? } - -#### Defined in - -[index.ts:137](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L137) - -___ - -### getTransactionStatus - -▸ **getTransactionStatus**(`txId`): `Promise`<`object`\> - -Gets the status of a transaction. - -[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `txId` | `number` | - -#### Returns - -`Promise`<`object`\> - -the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN } - -#### Defined in - -[index.ts:118](https://github.com/seanjameshan/starknet.js/blob/505f231/src/index.ts#L118) From 6917a99ee37eb0f839bd443060d88a8c7a4a6cbd Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 09:37:49 +0200 Subject: [PATCH 02/16] docs: ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 14109b61a..f737d86c4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ dist npm-debug.log .env .DS_Store + +docs/README.md From 6a242cedc0a261c55a433ee5a82f0acf28cfcdc2 Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 09:39:01 +0200 Subject: [PATCH 03/16] fix: tests --- __tests__/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 2ab40f4c3..087ce5959 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -1,4 +1,4 @@ -import * as starknet from '../index'; +import * as starknet from '../'; describe('starknet endpoints', () => { describe('feeder gateway endpoints', () => { From 857efc2e75d52572952291d2df79cf4b824f7ffc Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 09:39:11 +0200 Subject: [PATCH 04/16] docs: add ci job --- .github/workflows/node.js.yml | 38 +++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 000000000..f8072cf4e --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,38 @@ +name: Node.js CI +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + build-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - 14.x + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build --if-present + - run: npm test + generate-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 14.x + - run: npm ci + - run: npm run docs + - name: Do git actions + run: | + git add --force -- docs/README.md + git commit -m "docs: add generated docs" + git push diff --git a/README.md b/README.md index 8b5209265..f799c002c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@

+ From 31d1b8d7717145a5dd7beef606a9c253d1ceb62d Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 09:41:03 +0200 Subject: [PATCH 05/16] fix: ci job --- .github/workflows/node.js.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index f8072cf4e..b8ca47a9f 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -33,6 +33,8 @@ jobs: - run: npm run docs - name: Do git actions run: | + git config user.email "janek@argent.xyz" + git config user.name "Docs Bot" git add --force -- docs/README.md git commit -m "docs: add generated docs" git push From 6e13b1ca9d46663d5631213b14be20eb402e11a9 Mon Sep 17 00:00:00 2001 From: Docs Bot Date: Tue, 19 Oct 2021 07:41:40 +0000 Subject: [PATCH 06/16] docs: add generated docs --- docs/README.md | 222 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..313ee1357 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,222 @@ +StarkNet.js Docs + +# StarkNet.js Docs + +## Table of contents + +### Functions + +- [addTransaction](README.md#addtransaction) +- [callContract](README.md#callcontract) +- [getBlock](README.md#getblock) +- [getCode](README.md#getcode) +- [getContractAddresses](README.md#getcontractaddresses) +- [getStorageAt](README.md#getstorageat) +- [getTransaction](README.md#gettransaction) +- [getTransactionStatus](README.md#gettransactionstatus) + +## Functions + +### addTransaction + +▸ **addTransaction**(`tx`): `Promise`<`object`\> + +Invoke a function on the starknet contract + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17) + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `tx` | `object` | transaction to be invoked (WIP) | + +#### Returns + +`Promise`<`object`\> + +a confirmation of invoking a function on the starknet contract + +#### Defined in + +[index.ts:156](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L156) + +___ + +### callContract + +▸ **callContract**(`invokeTx`, `blockId`): `Promise`<`object`\> + +Calls a function on the StarkNet contract. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25) + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `invokeTx` | `object` | transaction to be invoked (WIP) | +| `blockId` | `number` | | + +#### Returns + +`Promise`<`object`\> + +the result of the function on the smart contract. + +#### Defined in + +[index.ts:33](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L33) + +___ + +### getBlock + +▸ **getBlock**(`blockId`): `Promise`<`object`\> + +Gets the block information from a block ID. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `blockId` | `number` | + +#### Returns + +`Promise`<`object`\> + +the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions } + +#### Defined in + +[index.ts:52](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L52) + +___ + +### getCode + +▸ **getCode**(`contractAddress`, `blockId`): `Promise`<`object`\> + +Gets the code of the deployed contract. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `contractAddress` | `string` | +| `blockId` | `number` | + +#### Returns + +`Promise`<`object`\> + +ABI of compiled contract in JSON + +#### Defined in + +[index.ts:72](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L72) + +___ + +### getContractAddresses + +▸ **getContractAddresses**(): `Promise`<`object`\> + +Gets the smart contract address on the goerli testnet. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15) + +#### Returns + +`Promise`<`object`\> + +starknet smart contract address + +#### Defined in + +[index.ts:13](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L13) + +___ + +### getStorageAt + +▸ **getStorageAt**(`contractAddress`, `key`, `blockId`): `Promise`<`object`\> + +Gets the contract's storage variable at a specific key. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46) + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `contractAddress` | `string` | | +| `key` | `number` | from getStorageVarAddress('') (WIP) | +| `blockId` | `number` | | + +#### Returns + +`Promise`<`object`\> + +the value of the storage variable + +#### Defined in + +[index.ts:93](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L93) + +___ + +### getTransaction + +▸ **getTransaction**(`txId`): `Promise`<`object`\> + +Gets the transaction information from a tx id. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `txId` | `number` | + +#### Returns + +`Promise`<`object`\> + +the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? } + +#### Defined in + +[index.ts:137](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L137) + +___ + +### getTransactionStatus + +▸ **getTransactionStatus**(`txId`): `Promise`<`object`\> + +Gets the status of a transaction. + +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `txId` | `number` | + +#### Returns + +`Promise`<`object`\> + +the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN } + +#### Defined in + +[index.ts:118](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L118) From 6a0a9893c1298a815aec21abda20f78ac697a4bf Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 09:50:39 +0200 Subject: [PATCH 07/16] fix: badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f799c002c..e9c889f8a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

- + From cf36305870a46c60507aa218c79899d6d3ea674c Mon Sep 17 00:00:00 2001 From: Docs Bot Date: Tue, 19 Oct 2021 07:51:14 +0000 Subject: [PATCH 08/16] docs: add generated docs --- docs/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/README.md b/docs/README.md index 313ee1357..e690ccd82 100644 --- a/docs/README.md +++ b/docs/README.md @@ -39,7 +39,7 @@ a confirmation of invoking a function on the starknet contract #### Defined in -[index.ts:156](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L156) +[index.ts:156](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L156) ___ @@ -66,7 +66,7 @@ the result of the function on the smart contract. #### Defined in -[index.ts:33](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L33) +[index.ts:33](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L33) ___ @@ -92,7 +92,7 @@ the block object { block_id, previous_block_id, state_root, status, timestamp, t #### Defined in -[index.ts:52](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L52) +[index.ts:52](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L52) ___ @@ -119,7 +119,7 @@ ABI of compiled contract in JSON #### Defined in -[index.ts:72](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L72) +[index.ts:72](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L72) ___ @@ -139,7 +139,7 @@ starknet smart contract address #### Defined in -[index.ts:13](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L13) +[index.ts:13](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L13) ___ @@ -167,7 +167,7 @@ the value of the storage variable #### Defined in -[index.ts:93](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L93) +[index.ts:93](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L93) ___ @@ -193,7 +193,7 @@ the transacton object { transaction_id, status, transaction, block_id?, block_nu #### Defined in -[index.ts:137](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L137) +[index.ts:137](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L137) ___ @@ -219,4 +219,4 @@ the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | P #### Defined in -[index.ts:118](https://github.com/argentlabs/starknet.js/blob/31d1b8d/src/index.ts#L118) +[index.ts:118](https://github.com/argentlabs/starknet.js/blob/6a0a989/src/index.ts#L118) From 3760687a0c72da7ac8c0fd2427d471fe4bdf7202 Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:00:06 +0200 Subject: [PATCH 09/16] feat: start adding types --- src/index.d.ts | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 47 ++++++++++++++++++++++------------ 2 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 src/index.d.ts diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 000000000..12182e90a --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,68 @@ +export interface GetContractAddressesResponse { + Starknet: string; + GpsStatementVerifier: string; +} + +export type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'REJECTED' | 'ACCEPTED_ONCHAIN'; +export type Type = 'DEPLOY' | 'INVOKE_FUNCTION'; +export type EntryPointType = 'EXTERNAL'; + +export interface Transaction { + type: Type; + contract_address: string; + entry_point_type?: EntryPointType; + entry_point_selector?: string; + calldata?: string[]; +} + +export interface GetBlockResponse { + sequence_number: number; + state_root: string; + block_id: number; + transactions: { + [txid: string]: Transaction; + }; + timestamp: number; + transaction_receipts: { + [txid: string]: { + block_id: number; + transaction_id: number; + l2_to_l1_messages: { + to_address: string; + payload: string[]; + from_address: string; + }[]; + block_number: number; + status: Status; + transaction_index: number; + }; + }; + previous_block_id: number; + status: Status; +} + +export interface Abi { + inputs: { name: string; type: string }[]; + name: string; + outputs: { name: string; type: string }[]; + type: string; +} + +export interface GetCode { + bytecode: string[]; + abi: Abi[]; +} + +export interface GetTransactionStatusResponse { + tx_status: Status; + block_id: number; +} + +export interface GetTransactionResponse { + transaction_index: number; + transaction: Transaction; + block_id: number; + block_number: number; + status: Status; + transaction_id: number; +} diff --git a/src/index.ts b/src/index.ts index 19dbc567e..3da4c440e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,13 @@ import axios from 'axios'; +import type { + GetBlockResponse, + GetCode, + GetContractAddressesResponse, + GetTransactionResponse, + GetTransactionStatusResponse, +} from './index.d'; + const API_URL: string = 'https://alpha2.starknet.io/'; const FEEDER_GATEWAY_URL: string = `${API_URL}/feeder_gateway`; const GATEWAY_URL: string = `${API_URL}/gateway`; @@ -8,19 +16,20 @@ const GATEWAY_URL: string = `${API_URL}/gateway`; * Gets the smart contract address on the goerli testnet. * * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15) - * @returns starknet smart contract address + * @returns starknet smart contract addresses */ -export function getContractAddresses(): Promise { +export function getContractAddresses(): Promise { return new Promise((resolve, reject) => { axios - .get(`${FEEDER_GATEWAY_URL}/get_contract_addresses`) - .then((resp: any) => { + .get(`${FEEDER_GATEWAY_URL}/get_contract_addresses`) + .then((resp) => { resolve(resp.data); }) .catch(reject); }); } +// TODO: add proper type /** * Calls a function on the StarkNet contract. * @@ -49,10 +58,10 @@ export function callContract(invokeTx: object, blockId: number): Promise * @param blockId * @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions } */ -export function getBlock(blockId: number): Promise { +export function getBlock(blockId: number): Promise { return new Promise((resolve, reject) => { axios - .get(`${FEEDER_GATEWAY_URL}/get_block?blockId=${blockId}`) + .get(`${FEEDER_GATEWAY_URL}/get_block?blockId=${blockId}`) .then((resp: any) => { resolve(resp.data); }) @@ -67,19 +76,22 @@ export function getBlock(blockId: number): Promise { * * @param contractAddress * @param blockId - * @returns ABI of compiled contract in JSON + * @returns Bytecode and ABI of compiled contract */ -export function getCode(contractAddress: string, blockId: number): Promise { +export function getCode(contractAddress: string, blockId: number): Promise { return new Promise((resolve, reject) => { axios - .get(`${FEEDER_GATEWAY_URL}/get_code?contractAddress=${contractAddress}&blockId=${blockId}`) - .then((resp: any) => { + .get( + `${FEEDER_GATEWAY_URL}/get_code?contractAddress=${contractAddress}&blockId=${blockId}` + ) + .then((resp) => { resolve(resp.data); }) .catch(reject); }); } +// TODO: add proper type /** * Gets the contract's storage variable at a specific key. * @@ -115,11 +127,13 @@ export function getStorageAt( * @param txId * @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN } */ -export function getTransactionStatus(txId: number): Promise { +export function getTransactionStatus(txId: number): Promise { return new Promise((resolve, reject) => { axios - .get(`${FEEDER_GATEWAY_URL}/get_transaction_status?transactionId=${txId}`) - .then((resp: any) => { + .get( + `${FEEDER_GATEWAY_URL}/get_transaction_status?transactionId=${txId}` + ) + .then((resp) => { resolve(resp.data); }) .catch(reject); @@ -134,17 +148,18 @@ export function getTransactionStatus(txId: number): Promise { * @param txId * @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? } */ -export function getTransaction(txId: number): Promise { +export function getTransaction(txId: number): Promise { return new Promise((resolve, reject) => { axios - .get(`${FEEDER_GATEWAY_URL}/get_transaction?transactionId=${txId}`) - .then((resp: any) => { + .get(`${FEEDER_GATEWAY_URL}/get_transaction?transactionId=${txId}`) + .then((resp) => { resolve(resp.data); }) .catch(reject); }); } +// TODO: add proper type /** * Invoke a function on the starknet contract * From 571b1d5092ee18b9ed0828f1cbc834f4aece3363 Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:19:38 +0200 Subject: [PATCH 10/16] fix: ci git push --- .github/workflows/node.js.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b8ca47a9f..60952ce04 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -37,4 +37,9 @@ jobs: git config user.name "Docs Bot" git add --force -- docs/README.md git commit -m "docs: add generated docs" - git push + - name: Push to git branch for PR + if: ${{ github.head_ref != '' }} + run: git push origin HEAD:${{ github.head_ref }} + - name: Push to git branch for branch + if: ${{ github.head_ref == '' }} + run: git push From 5edeae17cb8136307258e1b19e36c34cd61708b1 Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:23:15 +0200 Subject: [PATCH 11/16] debug --- .github/workflows/node.js.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 60952ce04..c7757d5b0 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -39,7 +39,9 @@ jobs: git commit -m "docs: add generated docs" - name: Push to git branch for PR if: ${{ github.head_ref != '' }} - run: git push origin HEAD:${{ github.head_ref }} + run: | + echo ${{ github.head_ref }} + git push origin ${{ github.head_ref }} - name: Push to git branch for branch if: ${{ github.head_ref == '' }} run: git push From d46d175aa9d51f283e2dd9aeeac41ab50fa3ac2e Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:26:03 +0200 Subject: [PATCH 12/16] fix: pipeline --- .github/workflows/node.js.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c7757d5b0..63e40e131 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -35,13 +35,12 @@ jobs: run: | git config user.email "janek@argent.xyz" git config user.name "Docs Bot" + git pull git add --force -- docs/README.md git commit -m "docs: add generated docs" - name: Push to git branch for PR if: ${{ github.head_ref != '' }} - run: | - echo ${{ github.head_ref }} - git push origin ${{ github.head_ref }} + run: git push origin HEAD:${{ github.head_ref }} - name: Push to git branch for branch if: ${{ github.head_ref == '' }} run: git push From c7d56d06644108d71e1bea3e73554b5c4178b82e Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:27:34 +0200 Subject: [PATCH 13/16] fix: pipeline --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 63e40e131..4fe1175f4 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -35,7 +35,7 @@ jobs: run: | git config user.email "janek@argent.xyz" git config user.name "Docs Bot" - git pull + git pull ${{ github.head_ref }} git add --force -- docs/README.md git commit -m "docs: add generated docs" - name: Push to git branch for PR From f9186de8f72d80d212317d8c823b981b7df31920 Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:33:47 +0200 Subject: [PATCH 14/16] fix: pipeline --- .github/workflows/node.js.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4fe1175f4..4646e038b 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -3,9 +3,6 @@ on: push: branches: - main - pull_request: - branches: - - main jobs: build-and-test: runs-on: ubuntu-latest @@ -35,12 +32,6 @@ jobs: run: | git config user.email "janek@argent.xyz" git config user.name "Docs Bot" - git pull ${{ github.head_ref }} git add --force -- docs/README.md git commit -m "docs: add generated docs" - - name: Push to git branch for PR - if: ${{ github.head_ref != '' }} - run: git push origin HEAD:${{ github.head_ref }} - - name: Push to git branch for branch - if: ${{ github.head_ref == '' }} - run: git push + git push From e862cfbf13d9e6d3509b609a31f8ebad1a31569a Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:34:58 +0200 Subject: [PATCH 15/16] fix: split pipelines --- .github/workflows/docs-bot.yml | 22 ++++++++++++++++++++++ .github/workflows/node.js.yml | 20 ++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/docs-bot.yml diff --git a/.github/workflows/docs-bot.yml b/.github/workflows/docs-bot.yml new file mode 100644 index 000000000..64f5467b6 --- /dev/null +++ b/.github/workflows/docs-bot.yml @@ -0,0 +1,22 @@ +name: Node.js CI +on: + push: + branches: + - main +jobs: + generate-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 14.x + - run: npm ci + - run: npm run docs + - name: Do git actions + run: | + git config user.email "janek@argent.xyz" + git config user.name "Docs Bot" + git add --force -- docs/README.md + git commit -m "docs: add generated docs" + git push diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4646e038b..8c79fab94 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -3,6 +3,10 @@ on: push: branches: - main + pull_request: + branches: + - main + jobs: build-and-test: runs-on: ubuntu-latest @@ -19,19 +23,3 @@ jobs: - run: npm ci - run: npm run build --if-present - run: npm test - generate-docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: 14.x - - run: npm ci - - run: npm run docs - - name: Do git actions - run: | - git config user.email "janek@argent.xyz" - git config user.name "Docs Bot" - git add --force -- docs/README.md - git commit -m "docs: add generated docs" - git push From f16427f8a33b46a51d37ad7fbe8a3f34edcf344e Mon Sep 17 00:00:00 2001 From: Janek Rahrt Date: Tue, 19 Oct 2021 10:38:56 +0200 Subject: [PATCH 16/16] fix: naming pipeline --- .github/workflows/docs-bot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs-bot.yml b/.github/workflows/docs-bot.yml index 64f5467b6..981703ba8 100644 --- a/.github/workflows/docs-bot.yml +++ b/.github/workflows/docs-bot.yml @@ -1,4 +1,4 @@ -name: Node.js CI +name: Docs Bot on: push: branches: