Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "operator" mandatory, remove "data" from pool creation #40

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ PORT=3000
ETHCONNECT_URL=http://127.0.0.1:5102
ETHCONNECT_INSTANCE=/contracts/erc1155
ETHCONNECT_TOPIC=token
ETHCONNECT_IDENTITY=0x136e7a2eb8d1ed764ce229779370879eb0d738b2
ETHCONNECT_PREFIX=fly
AUTO_INIT=true
15 changes: 4 additions & 11 deletions src/tokens/tokens.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export class TokenPool {
type: TokenType;

@ApiProperty()
@IsOptional()
operator?: string;
@IsDefined()
operator: string;

@ApiProperty({ description: trackingIdDescription })
@IsOptional()
Expand All @@ -92,10 +92,6 @@ export class TokenPool {
@ApiProperty({ description: poolConfigDescription })
@IsOptional()
config?: any;

@ApiProperty()
@IsOptional()
data?: string; // TODO: remove
}

export class TokenBalanceQuery {
Expand Down Expand Up @@ -127,8 +123,8 @@ export class TokenTransfer {
tokenIndex?: string;

@ApiProperty()
@IsOptional()
operator?: string;
@IsDefined()
operator: string;

@ApiProperty()
@IsNotEmpty()
Expand Down Expand Up @@ -191,9 +187,6 @@ class tokenEventBase {
export class TokenPoolEvent extends tokenEventBase {
@ApiProperty()
standard: string;

@ApiProperty()
data?: string; // TODO: remove
}

export class TokenTransferEvent extends tokenEventBase {
Expand Down
10 changes: 3 additions & 7 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,25 @@ const transferSingleEventSignature = 'TransferSingle(address,address,address,uin
export class TokensService {
baseUrl: string;
instanceUrl: string;
identity: string;
shortPrefix: string;

constructor(private http: HttpService, proxy: EventStreamProxyGateway) {
proxy.addListener(new TokenListener());
}

configure(baseUrl: string, instanceUrl: string, identity: string, shortPrefix: string) {
configure(baseUrl: string, instanceUrl: string, shortPrefix: string) {
this.baseUrl = baseUrl;
this.instanceUrl = instanceUrl;
this.identity = identity;
this.shortPrefix = shortPrefix;
}

private postOptions(operator?: string, requestId?: string) {
private postOptions(operator: string, requestId?: string) {
const from = `${this.shortPrefix}-from`;
const sync = `${this.shortPrefix}-sync`;
const id = `${this.shortPrefix}-id`;
return {
params: {
[from]: operator ?? this.identity,
[from]: operator,
[sync]: 'false',
[id]: requestId,
},
Expand All @@ -96,7 +94,6 @@ export class TokensService {
async createPool(dto: TokenPool): Promise<AsyncResponse> {
const dataToPack: PackedTokenData = {
trackingId: dto.trackingId,
data: dto.data, // TODO: remove
};
const response = await lastValueFrom(
this.http.post<EthConnectAsyncResponse>(
Expand Down Expand Up @@ -245,7 +242,6 @@ class TokenListener implements EventListener {
type: unpackedId.isFungible ? TokenType.FUNGIBLE : TokenType.NONFUNGIBLE,
operator: data.operator,
trackingId: unpackedData.trackingId,
data: unpackedData.data, // TODO: remove
transaction: {
blockNumber: event.blockNumber,
transactionIndex: event.transactionIndex,
Expand Down
14 changes: 8 additions & 6 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('AppController (e2e)', () => {
await app.init();

app.get(EventStreamProxyGateway).configure('url', 'topic');
app.get(TokensService).configure(BASE_URL, INSTANCE_URL, IDENTITY, PREFIX);
app.get(TokensService).configure(BASE_URL, INSTANCE_URL, PREFIX);

(app.getHttpServer() as Server).listen();
server = request(app.getHttpServer());
Expand All @@ -140,7 +140,7 @@ describe('AppController (e2e)', () => {
type: TokenType.FUNGIBLE,
requestId: 'op1',
trackingId: 'tx1',
data: 'test',
operator: IDENTITY,
};
const response: EthConnectAsyncResponse = {
id: 'op1',
Expand All @@ -155,7 +155,7 @@ describe('AppController (e2e)', () => {
expect(http.post).toHaveBeenCalledWith(
`${INSTANCE_URL}/create`,
{
data: '0x7b22747261636b696e674964223a22747831222c2264617461223a2274657374227d',
data: '0x7b22747261636b696e674964223a22747831227d',
is_fungible: true,
},
{
Expand All @@ -171,7 +171,6 @@ describe('AppController (e2e)', () => {
it('Create non-fungible pool', async () => {
const request: TokenPool = {
type: TokenType.NONFUNGIBLE,
data: 'test',
operator: '0xabc',
};
const response: EthConnectAsyncResponse = {
Expand All @@ -187,7 +186,7 @@ describe('AppController (e2e)', () => {
expect(http.post).toHaveBeenCalledWith(
`${INSTANCE_URL}/create`,
{
data: '0x7b2264617461223a2274657374227d',
data: '0x7b7d',
is_fungible: false,
},
{
Expand All @@ -207,6 +206,7 @@ describe('AppController (e2e)', () => {
amount: '2',
trackingId: 'abc',
data: 'test',
operator: IDENTITY,
};
const response: EthConnectAsyncResponse = {
id: '1',
Expand Down Expand Up @@ -235,6 +235,7 @@ describe('AppController (e2e)', () => {
poolId: 'N1',
to: '1',
amount: '2',
operator: IDENTITY,
};
const response: EthConnectAsyncResponse = {
id: '1',
Expand Down Expand Up @@ -264,6 +265,7 @@ describe('AppController (e2e)', () => {
from: 'A',
amount: '1',
trackingId: 'tx1',
operator: IDENTITY,
};
const response: EthConnectAsyncResponse = {
id: '1',
Expand Down Expand Up @@ -293,6 +295,7 @@ describe('AppController (e2e)', () => {
from: '1',
to: '2',
amount: '2',
operator: IDENTITY,
};
const response: EthConnectAsyncResponse = {
id: '1',
Expand Down Expand Up @@ -372,7 +375,6 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-pool',
data: <TokenPoolEvent>{
data: 'test',
trackingId: 'tx1',
standard: 'ERC1155',
poolId: 'F1',
Expand Down