Skip to content

Commit

Permalink
Custom account avatars (#179)
Browse files Browse the repository at this point in the history
* add 16 avatars in full resolution

* add service account avatar, resize avatars to 500px

* add naive account indexing

* reorganize go code, add address index util

* rename interactions to go-bindings module, retrieve account index from the client-side

* show account avatar on details screen

* fix empty interaction parsing
  • Loading branch information
bartolomej authored Aug 19, 2023
1 parent 00c8fd3 commit 9ccb447
Show file tree
Hide file tree
Showing 47 changed files with 943 additions and 395 deletions.
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ src/app/homepage/pages/**/*.html
*.sqlite

openapi.json
src/interactions/bin
src/go-bindings/bin
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"copy-static-assets": "cp -r ./static ./dist",
"cleanup": "rm -rf node_modules && rm -rf dist",
"build": "nest build --path ./tsconfig.build.json && yarn run copy-static-assets && npm run build:bin",
"build:bin": "go build -o dist/interactions/bin/parser ../internal/main.go",
"build:bin": "go build -o dist/go-bindings/bin/internal ../internal/main.go",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "rm -rf dist && mkdir -p dist && yarn run copy-static-assets && npm run build:bin && nest start --debug --watch --preserveWatchOutput",
"start:prod": "node dist/main",
Expand Down
4 changes: 2 additions & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ServeStaticModule } from "@nestjs/serve-static";
import { join } from "path";
import { WalletModule } from "./wallet/wallet.module";
import { DataProcessingModule } from "./data-processing/data-processing.module";
import { InteractionsModule } from "./interactions/interactions.module";
import { GoBindingsModule } from "./go-bindings/go-bindings.module";

@Global()
@Module({
Expand All @@ -40,7 +40,7 @@ import { InteractionsModule } from "./interactions/interactions.module";
ProcessesModule,
WalletModule,
DataProcessingModule,
InteractionsModule,
GoBindingsModule,
],
controllers: [AppController],
})
Expand Down
4 changes: 2 additions & 2 deletions backend/src/data-processing/data-processing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ProcessorService } from "./processor.service";
import { FlowModule } from "../flow/flow.module";
import { ProcessesModule } from "../processes/processes.module";
import { WalletModule } from "../wallet/wallet.module";
import { InteractionsModule } from '../interactions/interactions.module';
import { GoBindingsModule } from "../go-bindings/go-bindings.module";

@Module({
imports: [
Expand All @@ -21,7 +21,7 @@ import { InteractionsModule } from '../interactions/interactions.module';
CoreModule,
ProcessesModule,
WalletModule,
InteractionsModule
GoBindingsModule,
],
providers: [ProcessorService],
exports: [ProcessorService],
Expand Down
11 changes: 6 additions & 5 deletions backend/src/data-processing/processor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
WellKnownAddressesOptions,
} from "../flow/services/emulator.service";
import { AsyncIntervalScheduler } from "../core/async-interval-scheduler";
import { InteractionsService } from "../interactions/interactions.service";
import { GoBindingsService } from "../go-bindings/go-bindings.service";

type BlockData = {
block: FlowBlock;
Expand Down Expand Up @@ -103,7 +103,7 @@ export class ProcessorService implements ProjectContextLifecycle {
private processManagerService: ProcessManagerService,
private commonService: CacheRemovalService,
private flowEmulatorService: FlowEmulatorService,
private interactionService: InteractionsService
private interactionService: GoBindingsService
) {
this.processingScheduler = new AsyncIntervalScheduler({
name: "Blockchain processing",
Expand Down Expand Up @@ -498,9 +498,10 @@ export class ProcessorService implements ProjectContextLifecycle {
flowTransaction: FlowTransaction;
flowTransactionStatus: FlowTransactionStatus;
}) {
const parsedInteraction = await this.interactionService.parse({
sourceCode: options.flowTransaction.script,
});
const parsedInteraction =
await this.interactionService.getParsedInteraction({
sourceCode: options.flowTransaction.script,
});
if (parsedInteraction.error) {
this.logger.error(
`Unexpected interaction parsing error: ${parsedInteraction.error}`
Expand Down
27 changes: 27 additions & 0 deletions backend/src/go-bindings/go-bindings.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
GetParsedInteractionRequest,
GetParsedInteractionResponse,
GetAddressIndexRequest,
GetAddressIndexResponse,
} from "@flowser/shared";
import { Body, Controller, Post } from "@nestjs/common";
import { GoBindingsService } from "./go-bindings.service";

@Controller("go-bindings")
export class GoBindingsController {
constructor(private readonly service: GoBindingsService) {}

@Post("get-parsed-interaction")
async getParsedInteraction(@Body() body: unknown) {
const request = GetParsedInteractionRequest.fromJSON(body);
const response = await this.service.getParsedInteraction(request);
return GetParsedInteractionResponse.toJSON(response);
}

@Post("get-address-index")
async getAddressIndex(@Body() body: unknown) {
const request = GetAddressIndexRequest.fromJSON(body);
const response = await this.service.getAddressIndex(request);
return GetAddressIndexResponse.toJSON(response);
}
}
10 changes: 10 additions & 0 deletions backend/src/go-bindings/go-bindings.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { GoBindingsService } from './go-bindings.service';
import { GoBindingsController } from './go-bindings.controller';

@Module({
providers: [GoBindingsService],
controllers: [GoBindingsController],
exports: [GoBindingsService]
})
export class GoBindingsModule {}
18 changes: 18 additions & 0 deletions backend/src/go-bindings/go-bindings.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from "@nestjs/testing";
import { GoBindingsService } from "./go-bindings.service";

describe("InteractionsService", () => {
let service: GoBindingsService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [GoBindingsService],
}).compile();

service = module.get<GoBindingsService>(GoBindingsService);
});

it("should be defined", () => {
expect(service).toBeDefined();
});
});
73 changes: 73 additions & 0 deletions backend/src/go-bindings/go-bindings.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Injectable } from "@nestjs/common";
import {
GetParsedInteractionRequest,
GetParsedInteractionResponse,
GetAddressIndexRequest,
GetAddressIndexResponse,
} from "@flowser/shared";
import { spawn } from "node:child_process";
import * as path from "path";

type ExecuteGoBinRequest = {
command: string;
arguments: string[];
stdIn?: string;
};

type ExecuteGoBinResponse = {
raw: string;
};

@Injectable()
export class GoBindingsService {
public async getParsedInteraction(
request: GetParsedInteractionRequest
): Promise<GetParsedInteractionResponse> {
const response = await this.execute({
command: "get-parsed-interaction",
arguments: [],
stdIn: request.sourceCode,
});

return GetParsedInteractionResponse.fromJSON(JSON.parse(response.raw));
}

public async getAddressIndex(
request: GetAddressIndexRequest
): Promise<GetAddressIndexResponse> {
const response = await this.execute({
command: "get-address-index",
arguments: [request.chainId, request.hexAddress],
});

return { index: Number(response.raw) };
}

private execute(request: ExecuteGoBinRequest): Promise<ExecuteGoBinResponse> {
return new Promise((resolve, reject) => {
const childProcess = spawn(path.join(__dirname, "bin/internal"), [
request.command,
...request.arguments,
]);

let rawResponse = "";
childProcess.stdout.on("data", (data) => {
rawResponse += data.toString();
});

if (request.stdIn !== undefined) {
childProcess.stdin.write(request.stdIn);
// Write null char to signal the end of input.
childProcess.stdin.write(new Uint8Array([0]));
}

childProcess.on("close", (code) => {
if (code !== 0) {
reject(`Interaction parser exited with code: ${code}`);
} else {
resolve({ raw: rawResponse });
}
});
});
}
}
18 changes: 0 additions & 18 deletions backend/src/interactions/interactions.controller.ts

This file was deleted.

10 changes: 0 additions & 10 deletions backend/src/interactions/interactions.module.ts

This file was deleted.

18 changes: 0 additions & 18 deletions backend/src/interactions/interactions.service.spec.ts

This file was deleted.

41 changes: 0 additions & 41 deletions backend/src/interactions/interactions.service.ts

This file was deleted.

Binary file added frontend/src/assets/images/avatars/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/images/avatars/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions frontend/src/assets/images/avatars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Toy Faces Library - 3D Avatars
------------------------
from amritpaldesign.com

Licenses Explained: https://amritpaldesign.com/licenses

Thanks for your support ;)
--------------------------

Please contact me if you have any questions via [email protected]
4 changes: 4 additions & 0 deletions frontend/src/assets/images/avatars/service.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9ccb447

Please sign in to comment.