Skip to content

Commit f378b62

Browse files
xiaowheatiwbrhwfy
authored andcommitted
Add Dockerfile for lightcone_v2.js and fix importing error when using ethereumjs-abi (#286)
1 parent 4d67606 commit f378b62

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

packages/lightcone_v2.js/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM node:10.16
2+
3+
# Install Protocol Buffers tool
4+
RUN apt-get -qq update && apt-get -qq install -y \
5+
unzip
6+
7+
RUN git clone https://github.com/grpc/grpc-web /github/grpc-web
8+
9+
RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/\
10+
protoc-3.7.1-linux-x86_64.zip -o /tmp/protoc.zip && \
11+
cd /tmp && \
12+
unzip -qq protoc.zip && \
13+
cp /tmp/bin/protoc /usr/local/bin/protoc
14+
15+
RUN curl -sSL https://github.com/grpc/grpc-web/releases/download/1.0.4/\
16+
protoc-gen-grpc-web-1.0.4-linux-x86_64 -o /usr/local/bin/protoc-gen-grpc-web && \
17+
chmod +x /usr/local/bin/protoc-gen-grpc-web
18+
19+
# Add files
20+
ADD tslint.json ./tslint.json
21+
ADD tsconfig.json ./tsconfig.json
22+
ADD globals.d.ts ./globals.d.ts
23+
ADD package.json ./package.json
24+
25+
ADD src ./src
26+
ADD test ./test
27+
28+
# Build package
29+
RUN npm install && npm run build

packages/lightcone_v2.js/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77

88
# Entrypoint of library
99
`src/index.ts`
10+
11+
# How to build a Docker?
12+
```
13+
docker build -t lightcone-v2-js -f Dockerfile .
14+
```
15+
16+
# How to run tests in Docker?
17+
```
18+
docker run --rm lightcone-v2-js sh -c 'npm run test'
19+
```

packages/lightcone_v2.js/src/lib/wallet/ethereum/contracts/Contract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AbiFunction from './AbiFunction';
22
import {toHex} from '../../common/formatter';
3-
import {methodID} from 'ethereumjs-abi';
3+
var ethereumjs_abi = require('ethereumjs-abi')
44

55
export default class Contract {
66

@@ -11,7 +11,7 @@ export default class Contract {
1111
this.abiFunctions = funAbi.reduce((acc, item) => {
1212
const inputTypes = item.inputs.map(({type}) => type);
1313
const key = `${item.name}(${inputTypes.toString()})`;
14-
const methodHash = methodID(item.name, inputTypes);
14+
const methodHash = ethereumjs_abi.methodID(item.name, inputTypes);
1515
return ({
1616
...acc,
1717
[item.name]: new AbiFunction(item),

packages/lightcone_v2.js/src/lib/wallet/ethereum/token.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import validator from './validator';
55
import Transaction from './transaction';
66
import request from '../common/request';
7-
import {rawDecode} from 'ethereumjs-abi'
87
import {toBuffer} from "../common/formatter";
98

9+
var ethereumjs_abi = require('ethereumjs-abi')
10+
1011
// HACK: What is the host in wallet/token?
1112
const host = 'host';
1213

@@ -140,19 +141,19 @@ export default class Token {
140141

141142
async getName() {
142143
const response = await this.getConfig('name');
143-
const results = rawDecode(['string'], toBuffer(response['result']));
144+
const results = ethereumjs_abi.rawDecode(['string'], toBuffer(response['result']));
144145
return results.length > 0 ? results[0] : '';
145146
}
146147

147148
async getSymbol() {
148149
const response = await this.getConfig('symbol');
149-
const results = rawDecode(['string'], toBuffer(response['result']));
150+
const results = ethereumjs_abi.rawDecode(['string'], toBuffer(response['result']));
150151
return results.length > 0 ? results[0] : '';
151152
}
152153

153154
async getDecimals() {
154155
const response = await this.getConfig('decimals');
155-
const results = rawDecode(['uint'], toBuffer(response['result']));
156+
const results = ethereumjs_abi.rawDecode(['uint'], toBuffer(response['result']));
156157
return results.length > 0 ? results[0].toNumber() : -1;
157158
}
158159

0 commit comments

Comments
 (0)