Skip to content

Commit

Permalink
PR review feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepesh K N committed Jul 10, 2019
1 parent 4c44e45 commit 1cb21bc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 11 additions & 2 deletions README.md
Expand Up @@ -31,7 +31,7 @@ npm install @openst/mosaic-contracts

#### Usage

```js
```typescript
// Load the contracts' meta-data from the package:
import { contracts } from "@openst/mosaic-contracts";

Expand All @@ -43,13 +43,22 @@ const anchorBinary = contracts.Anchor.bin;
`@openst/mosaic-contracts` also includes the contract interacts.

Example of using the contract interacts.
```js
```typescript
import { Interacts} from "@openst/mosaic-contracts";

const anchor:Anchor = Interacts.getAnchor(web3, '0xAnchorContractAddress');
const gateway:EIP20Gateway = Interacts.getEIP20Gateway(web3, '0xEIP20GatewayContactAddress');
```
Example with Web3 contracts.
```typescript
import { contracts } from "@openst/mosaic-contracts";

const jsonInterface = contracts.Anchor.abi;
const contract = new web3.eth.Contract(jsonInterface, address, options);

const anchor:Anchor = contract as Anchor;

```
### For Direct Users

This section is only required if you want to *set up a **new** mosaic chain.*
Expand Down
4 changes: 2 additions & 2 deletions index.ts
@@ -1,4 +1,4 @@
import * as contracts from './contract_build/contracts.json';
import Interacts from './interacts/Interacts';
import interacts from './interacts/Interacts';

export {contracts, Interacts};
export {contracts, interacts};
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -58,8 +58,8 @@
"scripts": {
"update": "git submodule update --init --recursive && npm ci",
"compile": "truffle compile",
"compile:ts": "tsc",
"compile:all": "truffle compile --all && tsc",
"compile:ts": "tsc --resolveJsonModule",
"compile:all": "truffle compile --all && tsc --resolveJsonModule",
"generate:test_proofs": "./proof_generation/main.sh",
"test": "npm run test:deployment_tool && npm run test:fuzzy_proof_generator && npm run test:integration && npm run test:unit && npm run build-package",
"test:range": "./tools/test_range.sh",
Expand All @@ -72,8 +72,9 @@
"deploy:gateway": "npm run compile && node tools/blue_deployment/scripts/step1_origin_contracts.js",
"lint": "eslint {test,test_integration,tools,proof_generation} -c .eslintrc.json --ext .js --ext .ts",
"generate:interacts": "ts-generator ts-generator.json && node tools/contract_interact_generator.js",
"clean": "rm -r contract_build/contracts.json dist/* interacts/* build/*",
"copy:interacts": "cp interacts/*.d.ts dist/interacts",
"prepare:publish": "rm -r contract_build/contracts.json dist/* interacts/* build/* && npm run compile && npm run build:package && npm run generate:interacts && npm run compile:ts && npm run copy:interacts"
"prepare:publish": "npm run compile && npm run build:package && npm run generate:interacts && npm run compile:ts && npm run copy:interacts"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions tools/contract_interact_generator.js
Expand Up @@ -43,7 +43,7 @@ if (!fs.existsSync(contractPath)) {
}

// This variable holds all the import statements as string.
let imports = 'import { ContractOptions } from "web3-eth-contract";\nimport * as contracts from "../contract_build/contracts.json";\n';
let imports = 'import { ContractOptions } from \'web3-eth-contract\';\nimport * as contracts from \'../contract_build/contracts.json\';\n';

// This variable holds all the interact factor methods as string.
let interacts = `const Interacts = {\n`;
Expand All @@ -57,7 +57,7 @@ contractNames.forEach((contract) => {
`../interacts/${contract}.d.ts`,
);
if (fs.existsSync(declarationFilePath)) {
imports = `${ imports }import { ${contract} } from "../interacts/${contract}";\n`;
imports = `${ imports }import { ${contract} } from \'./${contract}\';\n`;

interacts = `${ interacts }
/**
Expand All @@ -68,7 +68,7 @@ contractNames.forEach((contract) => {
*
* @returns The ${contract} contract interact object.
*/
get${contract}: (web3: any, address?: string, options?: ContractOptions)=> {
get${contract}: (web3: any, address?: string, options?: ContractOptions): ${contract} => {
const jsonInterface = contracts.${contract}.abi;
const contract = new web3.eth.Contract(jsonInterface, address, options);
return contract as ${contract};
Expand Down

0 comments on commit 1cb21bc

Please sign in to comment.