Skip to content

Commit

Permalink
Starting frontend backendless (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
directcuteo authored Jun 25, 2022
1 parent 74ac761 commit f076e40
Show file tree
Hide file tree
Showing 11 changed files with 29,310 additions and 163 deletions.
29,259 changes: 29,247 additions & 12 deletions mock/http/db.json

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions mock/http/routes.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
{
"/chains/main/blocks/head/header": "/chains-main-blocks-head-header",
"/chains/main/mempool/pending_operations": "/chains-main-mempool-pending_operations",
"/chains/main/blocks/head/context/constants": "/constants",
"/dev/chains/main/blocks?limit=:l": "/dev-chains-main-blocks?_limit=:l",
"/dev/chains/main/actions/blocks/:h": "/dev-chains-main-blocks?hash=:h",
"/dev/version/": "/dev-version",
"/monitor/commit_hash/": "/monitor-commit-hash",
"/network/peers": "/network-peers",
"/resources/tezedge": "/resources-tezedge",
"/stats/context?context_name=:x": "/resources-storage",
"/v1/tree?threshold=x&reverse=:y": "/resources-memory",
"/v1/tree?threshold=:x&reverse=:y": "/resources-memory",
"/dev/shell/automaton/actions_stats": "/resources-state",
"/dev/shell/automaton/block_stats/graph?limit=:x": "/mempool-block-application",
"/dev/shell/automaton/stats/current_head/application?level=:x": "/mempool-block-details",
"/dev/shell/automaton/mempool/operation_stats": "/mempool-statistics"
"/dev/shell/automaton/mempool/operation_stats": "/mempool-statistics",
"/dev/shell/automaton/stats/current_head/peers?level=:x": "/dev-shell-automaton-stats-current_head-peers",
"/chains/main/blocks/head/helpers/validators?level=2469850": "/chains-main-blocks-head-helpers-validators",
"/dev/shell/automaton/preendorsements_status?level=:x&round=:y&base_time=:z": "/mempool-preendorsements-delegates-status-updates",
"/dev/shell/automaton/endorsements_status?level=:x&round=:y&base_time=:z": "/mempool-endorsements-delegates-status-updates",
"/chains/main/blocks/head~2/metadata": "/chains-main-blocks-head2-metadata",
"/dev/rewards/cycle/495": "/dev-rewards-cycle-495",
"/dev/rewards/cycle/495/:anything": "/dev-rewards-cycle-495-hash",
"/dev/chains/main/blocks/?limit=100": "/storage-dev-chains-main-blocks",
"/stats/main/blocks/:anything": "/stats-main-blocks-hash",
"/chains/main/blocks/:anything": "/chains-main-blocks-hash",
"/dev/shell/automaton/storage/requests": "/dev-shell-automaton-storage-requests",
"/dev/shell/automaton/actions_graph": "/dev-shell-automaton-actions-graph",
"/chains/main/blocks/:block/context/contracts/:contract/script": "/chains-main-blocks-context-contracts-script",
"/chains/main/blocks/:block/helpers/scripts/trace_code": "/chains-main-blocks-helpers-scripts-trace-code",
"/chains/main/blocks/:block/context/contracts/:contract/balance": "/chains-main-blocks-context-contracts-balance",
"/chains/main/blocks/": "/chains-main-blocks-hash"
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,32 @@ export class SmartContractsFiltersComponent implements OnInit {

private listenToActiveNodeHeader(): void {
this.store.select(selectActiveNodeHeader)
.pipe(
untilDestroyed(this)
)
.pipe(untilDestroyed(this))
.subscribe((header: SettingsNodeEntityHeader) => {
if (!this.routedBlockHash) {
this.routedBlockHash = header.hash;
this.formGroup.get('blockHash').setValue(this.routedBlockHash);
this.store.dispatch<SmartContractsResetBlocksAction>({ type: SMART_CONTRACTS_RESET_BLOCKS, payload: { blocks: [header.predecessor, header.hash], activeIndex: 1 } });
this.router.navigate(['contracts', header.hash]);
this.store.dispatch<SmartContractsResetBlocksAction>({
type: SMART_CONTRACTS_RESET_BLOCKS,
payload: { blocks: [header.predecessor, header.hash], activeIndex: 1 }
});
this.router.navigate(['contracts', header.hash || '']);
}
});
}

private listenToRouteChange(): void {
this.store.select(getMergedRoute)
.pipe(
untilDestroyed(this)
)
.pipe(untilDestroyed(this))
.subscribe((route: MergedRoute) => {
this.routedContractHash = route.params.contractHash;
if (this.routedBlockHash !== route.params.blockHash) {
this.routedBlockHash = route.params.blockHash;
this.formGroup.get('blockHash').setValue(this.routedBlockHash);
this.store.dispatch<SmartContractsResetBlocksAction>({ type: SMART_CONTRACTS_RESET_BLOCKS, payload: { blocks: [this.routedBlockHash], activeIndex: 0 } });
this.store.dispatch<SmartContractsResetBlocksAction>({
type: SMART_CONTRACTS_RESET_BLOCKS,
payload: { blocks: [this.routedBlockHash], activeIndex: 0 }
});
}
});
}
Expand Down Expand Up @@ -103,30 +105,42 @@ export class SmartContractsFiltersComponent implements OnInit {
const value = this.formGroup.get('blockHash').value;
if (this.routedBlockHash !== value) {
this.routedBlockHash = value;
this.store.dispatch<SmartContractsResetBlocksAction>({ type: SMART_CONTRACTS_RESET_BLOCKS, payload: { blocks: [this.routedBlockHash], activeIndex: 0 } });
this.store.dispatch<SmartContractsResetBlocksAction>({
type: SMART_CONTRACTS_RESET_BLOCKS,
payload: { blocks: [this.routedBlockHash], activeIndex: 0 }
});
this.router.navigate(['contracts', this.routedBlockHash]);
}
}

loadPreviousBlock(): void {
this.routedBlockHash = this.blockHashContext.hashes[this.blockHashContext.activeIndex - 1];
this.formGroup.get('blockHash').setValue(this.routedBlockHash);
this.store.dispatch<SmartContractsLoadAction>({ type: SMART_CONTRACTS_LOAD, payload: { blockHash: this.routedBlockHash } });
this.store.dispatch<SmartContractsLoadAction>({
type: SMART_CONTRACTS_LOAD,
payload: { blockHash: this.routedBlockHash }
});
this.router.navigate(['contracts', this.routedBlockHash]);
}

loadNextBlock(): void {
this.routedBlockHash = this.blockHashContext.hashes[this.blockHashContext.activeIndex + 1];
this.formGroup.get('blockHash').setValue(this.routedBlockHash);
this.store.dispatch<SmartContractsLoadAction>({ type: SMART_CONTRACTS_LOAD, payload: { blockHash: this.routedBlockHash } });
this.store.dispatch<SmartContractsLoadAction>({
type: SMART_CONTRACTS_LOAD,
payload: { blockHash: this.routedBlockHash }
});
this.router.navigate(['contracts', this.routedBlockHash]);
}

loadLatestAppliedBlock(): void {
if (this.routedBlockHash !== this.latestAppliedBlockHash) {
this.routedBlockHash = this.latestAppliedBlockHash;
this.formGroup.get('blockHash').setValue(this.routedBlockHash);
this.store.dispatch<SmartContractsResetBlocksAction>({ type: SMART_CONTRACTS_RESET_BLOCKS, payload: { blocks: [this.routedBlockHash], activeIndex: 0 } });
this.store.dispatch<SmartContractsResetBlocksAction>({
type: SMART_CONTRACTS_RESET_BLOCKS,
payload: { blocks: [this.routedBlockHash], activeIndex: 0 }
});
this.router.navigate(['contracts', this.routedBlockHash]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Action } from '@ngrx/store';
import { SmartContractTrace } from '@shared/types/smart-contracts/smart-contract-trace.type';
import { SmartContractResult } from '@shared/types/smart-contracts/smart-contract-result.type';
import { SmartContract } from '@shared/types/smart-contracts/smart-contract.type';
Expand Down
20 changes: 14 additions & 6 deletions src/app/smart-contracts/smart-contracts/smart-contracts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SmartContractTrace } from '@shared/types/smart-contracts/smart-contract
import { collectScriptElements } from '@smart-contracts/smart-contracts/smart-contracts.factory';
import { SmartContractDebugPoint } from '@shared/types/smart-contracts/smart-contract-debug-point.type';
import { jsonStringifySortedProperties } from '@helpers/json.helper';
import { environment } from '@environment/environment';


@Injectable({
Expand Down Expand Up @@ -36,7 +37,7 @@ export class SmartContractsService {

private addTraceDifferencesToContract(api: string, previousBlockHash: string, contract: SmartContract) {
const body = SmartContractsService.buildGetTraceRequestBody(contract);
return this.http.post(`${api}/chains/main/blocks/${previousBlockHash}/helpers/scripts/trace_code`, body).pipe(
return this.performTraceHttpCall(api, previousBlockHash, body).pipe(
map((traceCodeResponse: any) => {
contract.isSameStorage =
jsonStringifySortedProperties(contract.blockStorage, 0) === jsonStringifySortedProperties(traceCodeResponse.storage, 0);
Expand Down Expand Up @@ -72,7 +73,7 @@ export class SmartContractsService {

private addBalanceToContract(api: string, previousBlockHash: string, contract: SmartContract): Observable<SmartContract> {
return this.http.get(`${api}/chains/main/blocks/${previousBlockHash}/context/contracts/${contract.hash}/balance`).pipe(
map((balance: string) => ({ ...contract, balance }))
map((balance: string | [string]) => ({ ...contract, balance: Array.isArray(balance) ? balance[0] : balance }))
);
}

Expand Down Expand Up @@ -180,13 +181,20 @@ export class SmartContractsService {
getContractTrace(api: string, blockHash: string, contract: SmartContract): Observable<{ trace: SmartContractTrace[], gasTrace: number[], result: SmartContractResult }> {
return (contract.balance ? of(contract) : this.addBalanceToContract(api, blockHash, contract)).pipe(
map(contractWithBalance => SmartContractsService.buildGetTraceRequestBody(contractWithBalance)),
switchMap(body => this.http.post<any>(`${api}/chains/main/blocks/${blockHash}/helpers/scripts/trace_code`, body).pipe(
map(response => this.mapNewGetContractTrace(response, contract)),
catchError(err => of(this.mapNewGetContractTrace(err.error, contract)))
))
switchMap(body => {
return this.performTraceHttpCall(api, blockHash, body).pipe(
map(response => this.mapNewGetContractTrace(response, contract)),
catchError(err => of(this.mapNewGetContractTrace(err.error, contract)))
);
})
);
}

private performTraceHttpCall(api: string, blockHash: string, body: any): Observable<any> {
const url = `${api}/chains/main/blocks/${blockHash}/helpers/scripts/trace_code`;
return environment.api[0].name.includes('mocked') ? this.http.get(url) : this.http.post<any>(url, body);
}

private mapNewGetContractTrace(response: any, contract: SmartContract): { trace: SmartContractTrace[], gasTrace: number[], result: SmartContractResult } {
let trace: SmartContractTrace[];
let gasTrace: number[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="payload-view f-12 d-flex flex-column h-100"
*ngIf="stateMachine$ | async as stateMachine">
<div class="d-flex flex-between">
<div class="d-flex flex-row">
<div class="padding-vertical-10 action-tabs">
<ng-container *ngIf="stateMachine.activeAction">
<span *ngFor="let tab of tabs"
Expand All @@ -10,11 +10,6 @@
</span>
</ng-container>
</div>
<div class="padding-vertical-10">
<div class="tab foreground-6 margin-right-10 pointer" [class.active]="activeTab === 'STATS'"
(click)="activeTab = 'STATS'">STATISTICS
</div>
</div>
</div>
<div class="overflow-auto foreground" fxFlex="calc(100% - 34px)"
[ngClass]="activeTab !== 'STATS' ? 'padding-left-10 padding-top-10' : ''">
Expand All @@ -32,7 +27,6 @@
<div *ngSwitchCase="'DIFFS'">
<ngx-object-diff [obj]="stateDifferences"></ngx-object-diff>
</div>
<!-- <app-state-machine-statistics *ngSwitchCase="'STATS'"></app-state-machine-statistics>-->
</ng-container>
</div>
</div>

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/app/state-machine/state-machine.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { StateMachineActionDetailsComponent } from './state-machine-action-detai
import { MatSliderModule } from '@angular/material/slider';
import { TezedgeNgxJsonViewerModule } from '@shared/components/custom-tezedge-components/tezedge-ngx-json-viewer/tezedge-ngx-json-viewer.module';
import { StateMachineFiltersComponent } from './state-machine-filters/state-machine-filters.component';
import { StateMachineStatisticsComponent } from './state-machine-statistics/state-machine-statistics.component';


@NgModule({
Expand All @@ -19,7 +18,6 @@ import { StateMachineStatisticsComponent } from './state-machine-statistics/stat
StateMachineTableComponent,
StateMachineActionDetailsComponent,
StateMachineFiltersComponent,
StateMachineStatisticsComponent,
],
imports: [
StateMachineRoutingModule,
Expand Down
4 changes: 2 additions & 2 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const EXPOSED_SERVER = {
export const environment = {
production: false,
api: [
// MOCK,
MOCK,
// DEVELOP,
// MASTER,
// EXPOSED_SERVER,
Expand All @@ -317,7 +317,7 @@ export const environment = {
// TRACE,
// PRECHECKER,
// DEBUG,
PROD,
// PROD,
// STORAGE,
// OCTEZ_DEVELOP,
// OCTEZ_MASTER,
Expand Down

0 comments on commit f076e40

Please sign in to comment.