From 8af5cb84186febc4f5c5f6764db57cca63a7cac4 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Sat, 20 Jul 2024 23:58:39 -0400 Subject: [PATCH] Best version yet --- app/app.go | 1 + app/history.go | 75 ++- app/message.go | 32 + app/names.go | 10 +- frontend/src/components/global/Aside.tsx | 1 - frontend/src/components/view/ViewStatus.tsx | 12 +- frontend/src/views/History/HistoryTable.tsx | 16 +- frontend/src/views/History/HistoryView.tsx | 9 +- frontend/wailsjs/go/app/App.d.ts | 7 +- frontend/wailsjs/go/app/App.js | 8 + frontend/wailsjs/go/models.ts | 627 ++------------------ main.go | 2 + 12 files changed, 203 insertions(+), 597 deletions(-) create mode 100644 app/message.go diff --git a/app/app.go b/app/app.go index 88dc08b..a237076 100644 --- a/app/app.go +++ b/app/app.go @@ -36,6 +36,7 @@ type App struct { titleTemplate *template.Template Series dalle.Series `json:"series"` names []types.Name + namesMap map[base.Address]types.Name dalleCache map[string]*dalle.DalleDress renderCtxs map[base.Address][]output.RenderCtx } diff --git a/app/history.go b/app/history.go index 68541c1..32ff7b1 100644 --- a/app/history.go +++ b/app/history.go @@ -7,13 +7,64 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" - "github.com/wailsapp/wails/v2/pkg/runtime" ) -var addrToHistoryMap = map[base.Address][]types.Transaction{} +type TransactionEx struct { + BlockNumber base.Blknum `json:"blockNumber"` + TransactionIndex base.Txnum `json:"transactionIndex"` + Timestamp base.Timestamp `json:"timestamp"` + Date string `json:"date"` + From base.Address `json:"from"` + FromName string `json:"fromName"` + To base.Address `json:"to"` + ToName string `json:"toName"` + Wei base.Wei `json:"wei"` + Ether string `json:"ether"` + Function string `json:"function"` + HasToken bool `json:"hasToken"` + IsError bool `json:"isError"` +} + +func NewTransactionEx(a *App, tx *types.Transaction) *TransactionEx { + fromName := a.namesMap[tx.From].Name + if len(fromName) == 0 { + fromName = tx.From.String() + } else if len(fromName) > 39 { + fromName = fromName[:39] + "..." + } + toName := a.namesMap[tx.To].Name + if len(toName) == 0 { + toName = tx.To.String() + } else if len(toName) > 39 { + toName = toName[:39] + "..." + } + ether := tx.Value.ToEtherStr(18) + if tx.Value.IsZero() { + ether = "-" + } else if len(ether) > 5 { + ether = ether[:5] + } + return &TransactionEx{ + BlockNumber: tx.BlockNumber, + TransactionIndex: tx.TransactionIndex, + Timestamp: tx.Timestamp, + Date: tx.Date(), + From: tx.From, + FromName: fromName, + To: tx.To, + ToName: toName, + Wei: tx.Value, + Ether: ether, + HasToken: tx.HasToken, + IsError: tx.IsError, + // Function: tx.Function(), + } +} + +var addrToHistoryMap = map[base.Address][]TransactionEx{} var m = sync.Mutex{} -func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction { +func (a *App) GetHistory(addr string, first, pageSize int) []TransactionEx { address := base.HexToAddress(addr) m.Lock() defer m.Unlock() @@ -37,12 +88,18 @@ func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction { if !ok { continue } - addrToHistoryMap[address] = append(addrToHistoryMap[address], *tx) + txEx := NewTransactionEx(a, tx) + // if strings.HasPrefix(txEx.ToName, "0x") { + addrToHistoryMap[address] = append(addrToHistoryMap[address], *txEx) if len(addrToHistoryMap[address])%pageSize == 0 { - runtime.EventsEmit(a.ctx, "Progress", len(addrToHistoryMap[address]), nItems) + a.SendMessage(address, Progress, &ProgressMsg{ + Have: int64(len(addrToHistoryMap[address])), + Want: nItems, + }) } + // } case err := <-opts.RenderCtx.ErrorChan: - runtime.EventsEmit(a.ctx, "Error", err.Error()) + a.SendMessage(address, Error, err.Error()) default: if opts.RenderCtx.WasCanceled() { return @@ -53,11 +110,11 @@ func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction { _, _, err := opts.Export() if err != nil { - runtime.EventsEmit(a.ctx, "Error", err.Error()) - return []types.Transaction{} + a.SendMessage(address, Error, err.Error()) + return []TransactionEx{} } - runtime.EventsEmit(a.ctx, "Done") + a.SendMessage(address, Completed, "") } first = base.Max(0, base.Min(first, len(addrToHistoryMap[address])-1)) diff --git a/app/message.go b/app/message.go new file mode 100644 index 0000000..ff0f186 --- /dev/null +++ b/app/message.go @@ -0,0 +1,32 @@ +package app + +import ( + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/wailsapp/wails/v2/pkg/runtime" +) + +type Message int + +const ( + Completed Message = iota + Error + Progress +) + +type ProgressMsg struct { + Have int64 `json:"have"` + Want int64 `json:"want"` +} + +func (a *App) MessageType(msg Message) string { + m := map[Message]string{ + Completed: "Completed", + Error: "Error", + Progress: "Progress", + } + return m[msg] +} + +func (a *App) SendMessage(addr base.Address, msg Message, data interface{}) { + runtime.EventsEmit(a.ctx, a.MessageType(msg), data) +} diff --git a/app/names.go b/app/names.go index 7e3b9e3..2436dbf 100644 --- a/app/names.go +++ b/app/names.go @@ -3,6 +3,7 @@ package app import ( "github.com/TrueBlocks/trueblocks-core/sdk/v3" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -21,15 +22,22 @@ func (a *App) GetNamesCnt() int { } func (a *App) loadNames() error { + var err error + + types := names.Regular | names.Custom | names.Prefund | names.Baddress + if a.namesMap, err = names.LoadNamesMap("mainnet", types, nil); err != nil { + return err + } + opts := sdk.NamesOptions{ Regular: true, // Custom: true, + // Prefund: true, Globals: sdk.Globals{ Chain: "mainnet", }, } - var err error if a.names, _, err = opts.Names(); err != nil { return err } else { diff --git a/frontend/src/components/global/Aside.tsx b/frontend/src/components/global/Aside.tsx index 9c25acb..c4ba19a 100644 --- a/frontend/src/components/global/Aside.tsx +++ b/frontend/src/components/global/Aside.tsx @@ -1,5 +1,4 @@ import React, { useEffect } from "react"; -import { EventsOn, EventsOff } from "@runtime"; import { Text } from "@mantine/core"; export function Aside() { diff --git a/frontend/src/components/view/ViewStatus.tsx b/frontend/src/components/view/ViewStatus.tsx index 672ac70..5fc1724 100644 --- a/frontend/src/components/view/ViewStatus.tsx +++ b/frontend/src/components/view/ViewStatus.tsx @@ -2,6 +2,12 @@ import React, { ReactNode, useState, useEffect } from "react"; import classes from "./ViewStatus.module.css"; import { EventsOn, EventsOff } from "@runtime"; import { Text } from "@mantine/core"; +import { MessageType } from "@gocode/app/App"; + +type Progress = { + have: number; + want: number; +}; export function ViewStatus() { const [statusMessage, setStatusMessage] = useState(""); @@ -13,8 +19,8 @@ export function ViewStatus() { setColor(classes.green); }; - const handleProgress = (x: number, y: number) => { - setStatusMessage(`Progress: ${x}/${y}`); + const handleProgress = (p: Progress) => { + setStatusMessage(`Progress: ${p.have}/${p.want}`); setColor(classes.green); }; @@ -23,7 +29,7 @@ export function ViewStatus() { setColor(classes.red); }; - EventsOn("Done", handleDone); + EventsOn("Completed", handleDone); EventsOn("Progress", handleProgress); EventsOn("Error", handleError); diff --git a/frontend/src/views/History/HistoryTable.tsx b/frontend/src/views/History/HistoryTable.tsx index 0f26292..13aa828 100644 --- a/frontend/src/views/History/HistoryTable.tsx +++ b/frontend/src/views/History/HistoryTable.tsx @@ -1,9 +1,9 @@ import React from "react"; import { IconCircleCheck } from "@tabler/icons-react"; -import { types } from "@gocode/models"; +import { app } from "@gocode/models"; import { createColumnHelper } from "@tanstack/react-table"; -const txColumnHelper = createColumnHelper(); +const txColumnHelper = createColumnHelper(); export const txColumns = [ txColumnHelper.accessor("blockNumber", { @@ -16,23 +16,23 @@ export const txColumns = [ cell: (info) => info.renderValue(), size: 100, }), - txColumnHelper.accessor("timestamp", { - header: () => "Timestamp", + txColumnHelper.accessor("date", { + header: () => "Date", cell: (info) => info.renderValue(), size: 100, }), - txColumnHelper.accessor("from", { + txColumnHelper.accessor("fromName", { header: () => "From", cell: (info) => info.renderValue(), size: 100, }), - txColumnHelper.accessor("to", { + txColumnHelper.accessor("toName", { header: () => "To", cell: (info) => info.renderValue(), size: 100, }), - txColumnHelper.accessor("value", { - header: () => "Value", + txColumnHelper.accessor("ether", { + header: () => "Ether", cell: (info) => info.renderValue(), size: 100, }), diff --git a/frontend/src/views/History/HistoryView.tsx b/frontend/src/views/History/HistoryView.tsx index b033415..1909108 100644 --- a/frontend/src/views/History/HistoryView.tsx +++ b/frontend/src/views/History/HistoryView.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import classes from "@/App.module.css"; import { GetHistory, GetHistoryCnt } from "@gocode/app/App"; -import { types } from "@gocode/models"; +import { app } from "@gocode/models"; import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"; import { useHotkeys } from "react-hotkeys-hook"; import { Stack, Table, Title } from "@mantine/core"; @@ -10,16 +10,17 @@ import { View, ViewStatus } from "@components"; import { useKeyboardPaging2 } from "@hooks"; export function HistoryView() { - const [address, setAddress] = useState("0xee906d7d5f1748258174be4cbc38930302ab7b42"); + // const [address, setAddress] = useState("0x5088d623ba0fcf0131e0897a91734a4d83596aa0"); + // const [address, setAddress] = useState("0xee906d7d5f1748258174be4cbc38930302ab7b42"); // const [address, setAddress] = useState("0x8bae48f227d978d084b009b775222baaf61ed9fe"); // const [address, setAddress] = useState("0x3fb1cd2cd96c6d5c0b5eb3322d807b34482481d4"); // const [address, setAddress] = useState("0x5ed8cee6b63b1c6afce3ad7c92f4fd7e1b8fad9f"); // const [address, setAddress] = useState("0x1db3439a222c519ab44bb1144fc28167b4fa6ee6"); // const [address, setAddress] = useState("0xd8da6bf26964af9d7eed9e03e53415d37aa96045"); // const [address, setAddress] = useState("0x9531c059098e3d194ff87febb587ab07b30b1306"); - // const [address, setAddress] = useState("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); + const [address, setAddress] = useState("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); const [nItems, setNItems] = useState(0); - const { items, curItem } = useKeyboardPaging2( + const { items, curItem } = useKeyboardPaging2( (curItem, perPage) => GetHistory(address, curItem, perPage), nItems, address, diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index 97f44ae..4dd9748 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -1,6 +1,7 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT import {base} from '../models'; +import {app} from '../models'; import {types} from '../models'; import {config} from '../models'; import {dalle} from '../models'; @@ -22,7 +23,7 @@ export function GetFilelist(arg1:string):Promise>; export function GetFilename(arg1:string):Promise; -export function GetHistory(arg1:string,arg2:number,arg3:number):Promise>; +export function GetHistory(arg1:string,arg2:number,arg3:number):Promise>; export function GetHistoryCnt(arg1:string):Promise; @@ -50,12 +51,16 @@ export function LoadSeries():Promise; export function MakeDalleDress(arg1:string):Promise; +export function MessageType(arg1:app.Message):Promise; + export function RegisterRenderCtx(arg1:base.Address,arg2:output.RenderCtx):Promise; export function ReloadDatabases():Promise; export function Save(arg1:string):Promise; +export function SendMessage(arg1:base.Address,arg2:app.Message,arg3:any):Promise; + export function SetLast(arg1:string,arg2:string):Promise; export function String():Promise; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 27f1abd..6e5c3b0 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -90,6 +90,10 @@ export function MakeDalleDress(arg1) { return window['go']['app']['App']['MakeDalleDress'](arg1); } +export function MessageType(arg1) { + return window['go']['app']['App']['MessageType'](arg1); +} + export function RegisterRenderCtx(arg1, arg2) { return window['go']['app']['App']['RegisterRenderCtx'](arg1, arg2); } @@ -102,6 +106,10 @@ export function Save(arg1) { return window['go']['app']['App']['Save'](arg1); } +export function SendMessage(arg1, arg2, arg3) { + return window['go']['app']['App']['SendMessage'](arg1, arg2, arg3); +} + export function SetLast(arg1, arg2) { return window['go']['app']['App']['SetLast'](arg1, arg2); } diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index bfd6967..e7a2b2c 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -1,27 +1,75 @@ -export namespace base { +export namespace app { - export class Address { - address: number[]; + export class TransactionEx { + blockNumber: number; + transactionIndex: number; + timestamp: number; + date: string; + from: base.Address; + fromName: string; + to: base.Address; + toName: string; + // Go type: base + wei: any; + ether: string; + function: string; + hasToken: boolean; + isError: boolean; static createFrom(source: any = {}) { - return new Address(source); + return new TransactionEx(source); } constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); - this.address = source["address"]; + this.blockNumber = source["blockNumber"]; + this.transactionIndex = source["transactionIndex"]; + this.timestamp = source["timestamp"]; + this.date = source["date"]; + this.from = this.convertValues(source["from"], base.Address); + this.fromName = source["fromName"]; + this.to = this.convertValues(source["to"], base.Address); + this.toName = source["toName"]; + this.wei = this.convertValues(source["wei"], null); + this.ether = source["ether"]; + this.function = source["function"]; + this.hasToken = source["hasToken"]; + this.isError = source["isError"]; } + + convertValues(a: any, classs: any, asMap: boolean = false): any { + if (!a) { + return a; + } + if (a.slice && a.map) { + return (a as any[]).map(elem => this.convertValues(elem, classs)); + } else if ("object" === typeof a) { + if (asMap) { + for (const key of Object.keys(a)) { + a[key] = new classs(a[key]); + } + return a; + } + return new classs(a); + } + return a; + } } - export class Hash { - hash: number[]; + +} + +export namespace base { + + export class Address { + address: number[]; static createFrom(source: any = {}) { - return new Hash(source); + return new Address(source); } constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); - this.hash = source["hash"]; + this.address = source["address"]; } } @@ -194,144 +242,6 @@ export namespace output { export namespace types { - export class Parameter { - components?: Parameter[]; - indexed?: boolean; - internalType?: string; - name: string; - strDefault?: string; - type: string; - value?: any; - - static createFrom(source: any = {}) { - return new Parameter(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.components = this.convertValues(source["components"], Parameter); - this.indexed = source["indexed"]; - this.internalType = source["internalType"]; - this.name = source["name"]; - this.strDefault = source["strDefault"]; - this.type = source["type"]; - this.value = source["value"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class Function { - anonymous?: boolean; - constant?: boolean; - encoding: string; - inputs: Parameter[]; - message?: string; - name: string; - outputs: Parameter[]; - signature?: string; - stateMutability?: string; - type: string; - - static createFrom(source: any = {}) { - return new Function(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.anonymous = source["anonymous"]; - this.constant = source["constant"]; - this.encoding = source["encoding"]; - this.inputs = this.convertValues(source["inputs"], Parameter); - this.message = source["message"]; - this.name = source["name"]; - this.outputs = this.convertValues(source["outputs"], Parameter); - this.signature = source["signature"]; - this.stateMutability = source["stateMutability"]; - this.type = source["type"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class Log { - address: base.Address; - articulatedLog?: Function; - blockHash: base.Hash; - blockNumber: number; - data?: string; - logIndex: number; - timestamp?: number; - topics?: base.Hash[]; - transactionHash: base.Hash; - transactionIndex: number; - - static createFrom(source: any = {}) { - return new Log(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.address = this.convertValues(source["address"], base.Address); - this.articulatedLog = this.convertValues(source["articulatedLog"], Function); - this.blockHash = this.convertValues(source["blockHash"], base.Hash); - this.blockNumber = source["blockNumber"]; - this.data = source["data"]; - this.logIndex = source["logIndex"]; - this.timestamp = source["timestamp"]; - this.topics = this.convertValues(source["topics"], base.Hash); - this.transactionHash = this.convertValues(source["transactionHash"], base.Hash); - this.transactionIndex = source["transactionIndex"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } export class Name { address: base.Address; @@ -388,429 +298,6 @@ export namespace types { return a; } } - - export class Receipt { - blockHash?: base.Hash; - blockNumber: number; - contractAddress?: base.Address; - cumulativeGasUsed?: number; - effectiveGasPrice?: number; - from?: base.Address; - gasUsed: number; - isError?: boolean; - logs: Log[]; - status: number; - to?: base.Address; - transactionHash: base.Hash; - transactionIndex: number; - - static createFrom(source: any = {}) { - return new Receipt(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.blockHash = this.convertValues(source["blockHash"], base.Hash); - this.blockNumber = source["blockNumber"]; - this.contractAddress = this.convertValues(source["contractAddress"], base.Address); - this.cumulativeGasUsed = source["cumulativeGasUsed"]; - this.effectiveGasPrice = source["effectiveGasPrice"]; - this.from = this.convertValues(source["from"], base.Address); - this.gasUsed = source["gasUsed"]; - this.isError = source["isError"]; - this.logs = this.convertValues(source["logs"], Log); - this.status = source["status"]; - this.to = this.convertValues(source["to"], base.Address); - this.transactionHash = this.convertValues(source["transactionHash"], base.Hash); - this.transactionIndex = source["transactionIndex"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class Rewards { - // Go type: base - block: any; - // Go type: base - nephew: any; - // Go type: base - txFee: any; - // Go type: base - uncle: any; - - static createFrom(source: any = {}) { - return new Rewards(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.block = this.convertValues(source["block"], null); - this.nephew = this.convertValues(source["nephew"], null); - this.txFee = this.convertValues(source["txFee"], null); - this.uncle = this.convertValues(source["uncle"], null); - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class TraceResult { - address?: base.Address; - code?: string; - gasUsed?: number; - output?: string; - - static createFrom(source: any = {}) { - return new TraceResult(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.address = this.convertValues(source["address"], base.Address); - this.code = source["code"]; - this.gasUsed = source["gasUsed"]; - this.output = source["output"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class TraceAction { - address?: base.Address; - author?: base.Address; - // Go type: base - balance?: any; - callType: string; - from: base.Address; - gas: number; - init?: string; - input?: string; - refundAddress?: base.Address; - rewardType?: string; - selfDestructed?: base.Address; - to: base.Address; - // Go type: base - value: any; - - static createFrom(source: any = {}) { - return new TraceAction(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.address = this.convertValues(source["address"], base.Address); - this.author = this.convertValues(source["author"], base.Address); - this.balance = this.convertValues(source["balance"], null); - this.callType = source["callType"]; - this.from = this.convertValues(source["from"], base.Address); - this.gas = source["gas"]; - this.init = source["init"]; - this.input = source["input"]; - this.refundAddress = this.convertValues(source["refundAddress"], base.Address); - this.rewardType = source["rewardType"]; - this.selfDestructed = this.convertValues(source["selfDestructed"], base.Address); - this.to = this.convertValues(source["to"], base.Address); - this.value = this.convertValues(source["value"], null); - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class Trace { - action?: TraceAction; - articulatedTrace?: Function; - blockHash: base.Hash; - blockNumber: number; - error?: string; - result?: TraceResult; - subtraces: number; - timestamp: number; - traceAddress: number[]; - transactionHash: base.Hash; - transactionIndex: number; - type?: string; - transactionPosition?: number; - - static createFrom(source: any = {}) { - return new Trace(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.action = this.convertValues(source["action"], TraceAction); - this.articulatedTrace = this.convertValues(source["articulatedTrace"], Function); - this.blockHash = this.convertValues(source["blockHash"], base.Hash); - this.blockNumber = source["blockNumber"]; - this.error = source["error"]; - this.result = this.convertValues(source["result"], TraceResult); - this.subtraces = source["subtraces"]; - this.timestamp = source["timestamp"]; - this.traceAddress = source["traceAddress"]; - this.transactionHash = this.convertValues(source["transactionHash"], base.Hash); - this.transactionIndex = source["transactionIndex"]; - this.type = source["type"]; - this.transactionPosition = source["transactionPosition"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - - - export class Statement { - accountedFor: base.Address; - // Go type: base - amountIn?: any; - // Go type: base - amountOut?: any; - assetAddr: base.Address; - assetSymbol: string; - // Go type: base - begBal: any; - blockNumber: number; - // Go type: base - correctingIn?: any; - // Go type: base - correctingOut?: any; - correctingReason?: string; - decimals: number; - // Go type: base - endBal: any; - // Go type: base - gasOut?: any; - // Go type: base - internalIn?: any; - // Go type: base - internalOut?: any; - logIndex: number; - // Go type: base - minerBaseRewardIn?: any; - // Go type: base - minerNephewRewardIn?: any; - // Go type: base - minerTxFeeIn?: any; - // Go type: base - minerUncleRewardIn?: any; - // Go type: base - prefundIn?: any; - // Go type: base - prevBal?: any; - priceSource: string; - recipient: base.Address; - // Go type: base - selfDestructIn?: any; - // Go type: base - selfDestructOut?: any; - sender: base.Address; - spotPrice: number; - timestamp: number; - transactionHash: base.Hash; - transactionIndex: number; - - static createFrom(source: any = {}) { - return new Statement(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.accountedFor = this.convertValues(source["accountedFor"], base.Address); - this.amountIn = this.convertValues(source["amountIn"], null); - this.amountOut = this.convertValues(source["amountOut"], null); - this.assetAddr = this.convertValues(source["assetAddr"], base.Address); - this.assetSymbol = source["assetSymbol"]; - this.begBal = this.convertValues(source["begBal"], null); - this.blockNumber = source["blockNumber"]; - this.correctingIn = this.convertValues(source["correctingIn"], null); - this.correctingOut = this.convertValues(source["correctingOut"], null); - this.correctingReason = source["correctingReason"]; - this.decimals = source["decimals"]; - this.endBal = this.convertValues(source["endBal"], null); - this.gasOut = this.convertValues(source["gasOut"], null); - this.internalIn = this.convertValues(source["internalIn"], null); - this.internalOut = this.convertValues(source["internalOut"], null); - this.logIndex = source["logIndex"]; - this.minerBaseRewardIn = this.convertValues(source["minerBaseRewardIn"], null); - this.minerNephewRewardIn = this.convertValues(source["minerNephewRewardIn"], null); - this.minerTxFeeIn = this.convertValues(source["minerTxFeeIn"], null); - this.minerUncleRewardIn = this.convertValues(source["minerUncleRewardIn"], null); - this.prefundIn = this.convertValues(source["prefundIn"], null); - this.prevBal = this.convertValues(source["prevBal"], null); - this.priceSource = source["priceSource"]; - this.recipient = this.convertValues(source["recipient"], base.Address); - this.selfDestructIn = this.convertValues(source["selfDestructIn"], null); - this.selfDestructOut = this.convertValues(source["selfDestructOut"], null); - this.sender = this.convertValues(source["sender"], base.Address); - this.spotPrice = source["spotPrice"]; - this.timestamp = source["timestamp"]; - this.transactionHash = this.convertValues(source["transactionHash"], base.Hash); - this.transactionIndex = source["transactionIndex"]; - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } - export class Transaction { - articulatedTx?: Function; - blockHash: base.Hash; - blockNumber: number; - from: base.Address; - gas: number; - gasPrice: number; - gasUsed: number; - hasToken: boolean; - hash: base.Hash; - input: string; - isError: boolean; - maxFeePerGas: number; - maxPriorityFeePerGas: number; - nonce: number; - receipt?: Receipt; - timestamp: number; - to: base.Address; - traces: Trace[]; - transactionIndex: number; - type: string; - // Go type: base - value: any; - statements?: Statement[]; - - static createFrom(source: any = {}) { - return new Transaction(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.articulatedTx = this.convertValues(source["articulatedTx"], Function); - this.blockHash = this.convertValues(source["blockHash"], base.Hash); - this.blockNumber = source["blockNumber"]; - this.from = this.convertValues(source["from"], base.Address); - this.gas = source["gas"]; - this.gasPrice = source["gasPrice"]; - this.gasUsed = source["gasUsed"]; - this.hasToken = source["hasToken"]; - this.hash = this.convertValues(source["hash"], base.Hash); - this.input = source["input"]; - this.isError = source["isError"]; - this.maxFeePerGas = source["maxFeePerGas"]; - this.maxPriorityFeePerGas = source["maxPriorityFeePerGas"]; - this.nonce = source["nonce"]; - this.receipt = this.convertValues(source["receipt"], Receipt); - this.timestamp = source["timestamp"]; - this.to = this.convertValues(source["to"], base.Address); - this.traces = this.convertValues(source["traces"], Trace); - this.transactionIndex = source["transactionIndex"]; - this.type = source["type"]; - this.value = this.convertValues(source["value"], null); - this.statements = this.convertValues(source["statements"], Statement); - } - - convertValues(a: any, classs: any, asMap: boolean = false): any { - if (!a) { - return a; - } - if (a.slice && a.map) { - return (a as any[]).map(elem => this.convertValues(elem, classs)); - } else if ("object" === typeof a) { - if (asMap) { - for (const key of Object.keys(a)) { - a[key] = new classs(a[key]); - } - return a; - } - return new classs(a); - } - return a; - } - } } diff --git a/main.go b/main.go index 4ef8414..c738a7a 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,8 @@ func main() { a, &types.Name{}, &types.Transaction{}, + &app.TransactionEx{}, + &app.ProgressMsg{}, }, StartHidden: true, AssetServer: &assetserver.Options{