Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #36 from RetricSu/add-get-chain-info-rpc
Browse files Browse the repository at this point in the history
feat: add poly_getChainInfo rpc
  • Loading branch information
RetricSu authored Jul 27, 2021
2 parents 49b26d5 + 188c584 commit ba7d4f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 50 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DATABASE_URL=postgres://username:password@localhost:5432/your_db
GODWOKEN_JSON_RPC=<godwoken rpc>
ETH_ACCOUNT_LOCK_HASH=<eth account lock script hash>
ROLLUP_TYPE_HASH=<godwoken rollup type hash>
ROLLUP_CONFIG_HASH=<godwoken rollup config hash>
CHAIN_ID=<your chain id in integer>
CREATOR_ACCOUNT_ID=<your creator account id in integer>
ADDRESS_STORE_PATH_ABSOLUTE=<path for storing short-address vs eth-address mapping. if not provided, will use default path: api-server/lib/hashmap-db>
Expand Down Expand Up @@ -111,8 +112,16 @@ yarn workspace @godwoken-web3/api-server start
- gw_submit_withdrawal_request

### poly
- poly_ethAddressToPolyjuiceAddress
- poly_polyjuiceAddressToEthAddress
- poly_getEthAddressByGodwokenShortAddress
- poly_saveEthAddressGodwokenShortAddressMapping
- poly_getChainInfo
- poly_getDefaultFromAddress
- poly_getContractValidatorTypeHash
- poly_getRollupTypeHash
- poly_getRollupConfigHash
- poly_getEthAccountLockHash
- poly_getCreatorId

## Examples
### web3_clientVersion

Expand Down
77 changes: 29 additions & 48 deletions packages/api-server/src/methods/modules/poly.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
ethAddressToPolyjuiceAddress,
polyjuiceAddressToEthAddress,
} from "../../convert-tx";
import { RPC } from "ckb-js-toolkit";
import { Callback } from "../types";
import { middleware, validators } from "../validator";
Expand All @@ -17,18 +13,6 @@ export class Poly {
this.rpc = new RPC(process.env.GODWOKEN_JSON_RPC as string);
this.hashMap = new HashMap();

this.ethAddressToPolyjuiceAddress = middleware(
this.ethAddressToPolyjuiceAddress.bind(this),
1,
[validators.address]
);

this.polyjuiceAddressToEthAddress = middleware(
this.polyjuiceAddressToEthAddress.bind(this),
1,
[validators.address]
);

this.getEthAddressByGodwokenShortAddress = middleware(
this.getEthAddressByGodwokenShortAddress.bind(this),
1,
Expand All @@ -42,38 +26,6 @@ export class Poly {
);
}

async ethAddressToPolyjuiceAddress(args: [string], callback: Callback) {
try {
const ethAddress = args[0];
const polyjuiceAddress = await ethAddressToPolyjuiceAddress(
ethAddress,
this.rpc
);
callback(null, polyjuiceAddress);
} catch (error) {
callback({
code: WEB3_ERROR,
message: error.message,
});
}
}

async polyjuiceAddressToEthAddress(args: [string], callback: Callback) {
try {
const polyjuiceAddress = args[0];
const ethAddress = await polyjuiceAddressToEthAddress(
polyjuiceAddress,
this.rpc
);
callback(null, ethAddress);
} catch (error) {
callback({
code: WEB3_ERROR,
message: error.message,
});
}
}

async getEthAddressByGodwokenShortAddress(
args: [string],
callback: Callback
Expand Down Expand Up @@ -155,6 +107,16 @@ export class Poly {
});
}

async getRollupConfigHash(args: [], callback: Callback) {
if (process.env.ROLLUP_TYPE_HASH)
callback(null, process.env.ROLLUP_CONFIG_HASH!);
else
callback({
code: WEB3_ERROR,
message: "ROLLUP_CONFIG_HASH not found!",
});
}

async getEthAccountLockHash(args: [], callback: Callback) {
if (process.env.ETH_ACCOUNT_LOCK_HASH)
callback(null, process.env.ETH_ACCOUNT_LOCK_HASH!);
Expand All @@ -164,4 +126,23 @@ export class Poly {
message: "ETH_ACCOUNT_LOCK_HASH not found!",
});
}

async getChainInfo(args: [], callback: Callback) {
try {
const chainInfo = {
rollupScriptHash: process.env.ROLLUP_TYPE_HASH,
rollupConfigHash: process.env.ROLLUP_CONFIG_HASH,
ethAccountLockTypeHash: process.env.ETH_ACCOUNT_LOCK_HASH,
polyjuiceContractTypeHash: process.env.POLYJUICE_VALIDATOR_TYPE_HASH,
polyjuiceCreatorId: process.env.CREATOR_ACCOUNT_ID,
chainId: process.env.CHAIN_ID,
};
callback(null, chainInfo);
} catch (error) {
callback({
code: WEB3_ERROR,
message: error.message,
});
}
}
}

0 comments on commit ba7d4f4

Please sign in to comment.