Skip to content

Commit

Permalink
Merge pull request #6 from hfuss/contract-gateway-support
Browse files Browse the repository at this point in the history
Support Using Either /abis or /gateways
  • Loading branch information
dechdev authored Jan 21, 2022
2 parents 2ab302d + 6eb6a66 commit 2bd77d8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PORT=3000
ETHCONNECT_URL=http://127.0.0.1:5102
ETHCONNECT_INSTANCE=/contracts/<Address of ERC20 Factory>
ETHCONNECT_INSTANCE=/contracts/<Address of ERC20 Factory> # if ethconnect has remote registry use /instances/<Address of ERC20 Factory>
ETHCONNECT_TOPIC=token
ETHCONNECT_PREFIX=fly
AUTO_INIT=true
CONTRACT_ABI_ID=<ABI ID of ERC20 contract instance>
ETHCONNECT_CONTRACT_URI=/abis/<ABI ID of ERC20 contract instance> # if ethconnect has remote registry use /gateways/<Gateway name of ERC20 contract>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ solidity/build

# IDEs and editors
/.idea
*.iml
.project
.classpath
.c9/
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function bootstrap() {
const topic = config.get<string>('ETHCONNECT_TOPIC', 'token20');
const shortPrefix = config.get<string>('ETHCONNECT_PREFIX', 'fly');
const autoInit = config.get<string>('AUTO_INIT', 'true');
const contractABI = config.get<string>('CONTRACT_ABI_ID', '');
const contractUri = config.get<string>('ETHCONNECT_CONTRACT_URI', '');
const username = config.get<string>('ETHCONNECT_USERNAME', '');
const password = config.get<string>('ETHCONNECT_PASSWORD', '');

Expand All @@ -71,7 +71,7 @@ async function bootstrap() {
app.get(EventStreamProxyGateway).configure(wsUrl, topic);
app
.get(TokensService)
.configure(ethConnectUrl, instancePath, topic, shortPrefix, contractABI, username, password);
.configure(ethConnectUrl, instancePath, topic, shortPrefix, contractUri, username, password);

if (autoInit !== 'false') {
await app.get(TokensService).init();
Expand Down
10 changes: 5 additions & 5 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TokensService {
instanceUrl: string;
topic: string;
shortPrefix: string;
contractABI: string;
contractUri: string;
contractInstanceUrl: string;
stream: EventStream;
username: string;
Expand All @@ -83,17 +83,17 @@ export class TokensService {
instancePath: string,
topic: string,
shortPrefix: string,
contractABI: string,
contractUri: string,
username: string,
password: string,
) {
this.baseUrl = baseUrl;
this.instancePath = instancePath;
this.instanceUrl = `${baseUrl}${instancePath}`;
this.instanceUrl = `${this.baseUrl}${this.instancePath}`;
this.topic = topic;
this.shortPrefix = shortPrefix;
this.contractABI = contractABI;
this.contractInstanceUrl = `${this.baseUrl}/abis/${contractABI}`;
this.contractUri = contractUri;
this.contractInstanceUrl = `${this.baseUrl}${this.contractUri}`;
this.username = username;
this.password = password;
this.proxy.addListener(new TokenListener(this, this.topic));
Expand Down
12 changes: 6 additions & 6 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { TokensService } from '../src/tokens/tokens.service';
import { AppModule } from './../src/app.module';

const BASE_URL = 'http://eth';
const CONTRACT_ABI = '123';
const CONTRACT_URI = '/abis/123';
const CONTRACT_ADDRESS = '0x123456';
const IDENTITY = '0x1';
const INSTANCE_PATH = '/tokens';
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('AppController (e2e)', () => {
await app.init();

app.get(EventStreamProxyGateway).configure('url', TOPIC);
app.get(TokensService).configure(BASE_URL, INSTANCE_PATH, TOPIC, PREFIX, CONTRACT_ABI, '', '');
app.get(TokensService).configure(BASE_URL, INSTANCE_PATH, TOPIC, PREFIX, CONTRACT_URI, '', '');

(app.getHttpServer() as Server).listen();
server = request(app.getHttpServer());
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('AppController (e2e)', () => {

expect(http.post).toHaveBeenCalledTimes(1);
expect(http.post).toHaveBeenCalledWith(
`${BASE_URL}/abis/${CONTRACT_ABI}/${CONTRACT_ADDRESS}/mintWithData`,
`${BASE_URL}${CONTRACT_URI}/${CONTRACT_ADDRESS}/mintWithData`,
{
amount: '2',
data: '0x74657374',
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('AppController (e2e)', () => {

expect(http.post).toHaveBeenCalledTimes(1);
expect(http.post).toHaveBeenCalledWith(
`${BASE_URL}/abis/${CONTRACT_ABI}/${CONTRACT_ADDRESS}/transferWithData`,
`${BASE_URL}${CONTRACT_URI}/${CONTRACT_ADDRESS}/transferWithData`,
{
amount: '2',
data: '0x00',
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('AppController (e2e)', () => {

expect(http.post).toHaveBeenCalledTimes(1);
expect(http.post).toHaveBeenCalledWith(
`${BASE_URL}/abis/${CONTRACT_ABI}/${CONTRACT_ADDRESS}/burnWithData`,
`${BASE_URL}${CONTRACT_URI}/${CONTRACT_ADDRESS}/burnWithData`,
{
data: '0x747831',
from: 'A',
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('AppController (e2e)', () => {

expect(http.get).toHaveBeenCalledTimes(1);
expect(http.get).toHaveBeenCalledWith(
`${BASE_URL}/abis/${CONTRACT_ABI}/${CONTRACT_ADDRESS}/balanceOf`,
`${BASE_URL}${CONTRACT_URI}/${CONTRACT_ADDRESS}/balanceOf`,
{
params: {
account: '1',
Expand Down
4 changes: 2 additions & 2 deletions test/ws.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { TokensService } from '../src/tokens/tokens.service';
import { WebSocketMessage } from '../src/websocket-events/websocket-events.base';

const BASE_URL = 'http://eth';
const CONTRACT_ABI = '123';
const CONTRACT_URI = '/abis/123';
const CONTRACT_ADDRESS = '0x123456';
const INSTANCE_PATH = '/tokens';
const ERC20_STANDARD = 'ERC20';
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('WebSocket AppController (e2e)', () => {
await app.init();

app.get(EventStreamProxyGateway).configure('url', TOPIC);
app.get(TokensService).configure(BASE_URL, INSTANCE_PATH, TOPIC, PREFIX, CONTRACT_ABI, '', '');
app.get(TokensService).configure(BASE_URL, INSTANCE_PATH, TOPIC, PREFIX, CONTRACT_URI, '', '');

(app.getHttpServer() as Server).listen();
server = request(app.getHttpServer());
Expand Down

0 comments on commit 2bd77d8

Please sign in to comment.