-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
161 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
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/logger" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" | ||
) | ||
|
||
var addrToHistoryMap = map[base.Address][]types.Transaction{} | ||
|
||
func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction { | ||
address := base.HexToAddress(addr) | ||
if address.IsZero() { | ||
return []types.Transaction{ | ||
{ | ||
TransactionIndex: 1, | ||
BlockNumber: 1, | ||
BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db01"), | ||
}, | ||
{ | ||
TransactionIndex: 2, | ||
BlockNumber: 2, | ||
BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db02"), | ||
}, | ||
{ | ||
TransactionIndex: 3, | ||
BlockNumber: 3, | ||
BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db03"), | ||
if len(addrToHistoryMap[address]) == 0 { | ||
opts := sdk.ExportOptions{ | ||
Addrs: []string{addr}, | ||
Articulate: true, | ||
Globals: sdk.Globals{ | ||
Cache: true, | ||
}, | ||
} | ||
} | ||
|
||
var ret []types.Transaction | ||
if len(addrToHistoryMap[address]) == 0 { | ||
return ret | ||
monitors, _, err := opts.Export() | ||
if err != nil { | ||
// EventEmitter.Emit("error", err) | ||
logger.Info(err) | ||
return []types.Transaction{} | ||
} else if len(monitors) == 0 { | ||
logger.Info("none") | ||
return []types.Transaction{} | ||
} else { | ||
logger.Info("got em", len(monitors)) | ||
addrToHistoryMap[address] = monitors | ||
} | ||
} | ||
first = base.Max(0, base.Min(first, len(addrToHistoryMap[address])-1)) | ||
last := base.Min(len(addrToHistoryMap[address]), first+pageSize) | ||
return addrToHistoryMap[address][first:last] | ||
} | ||
|
||
func (a *App) GetHistoryCnt(addr string) int { | ||
address := base.HexToAddress(addr) | ||
if address.IsZero() { | ||
return 3 | ||
func (a *App) GetHistoryCnt(addr string) int64 { | ||
opts := sdk.ListOptions{ | ||
Addrs: []string{addr}, | ||
} | ||
monitors, _, err := opts.ListCount() | ||
if err != nil { | ||
// EventEmitter.Emit("error", err) | ||
return 0 | ||
} else if len(monitors) == 0 { | ||
return 0 | ||
} | ||
return len(addrToHistoryMap[address]) | ||
return monitors[0].NRecords | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL | ||
// This file is automatically generated. DO NOT EDIT | ||
import {types} from '../models'; | ||
|
||
export function Date():Promise<string>; | ||
|
||
export function FinishUnmarshal():Promise<void>; | ||
|
||
export function GetKey():Promise<string>; | ||
|
||
export function Model(arg1:string,arg2:string,arg3:boolean,arg4:{[key: string]: any}):Promise<types.Model>; | ||
|
||
export function Orig():Promise<string>; | ||
|
||
export function String():Promise<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @ts-check | ||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL | ||
// This file is automatically generated. DO NOT EDIT | ||
|
||
export function Date() { | ||
return window['go']['types']['Appearance']['Date'](); | ||
} | ||
|
||
export function FinishUnmarshal() { | ||
return window['go']['types']['Appearance']['FinishUnmarshal'](); | ||
} | ||
|
||
export function GetKey() { | ||
return window['go']['types']['Appearance']['GetKey'](); | ||
} | ||
|
||
export function Model(arg1, arg2, arg3, arg4) { | ||
return window['go']['types']['Appearance']['Model'](arg1, arg2, arg3, arg4); | ||
} | ||
|
||
export function Orig() { | ||
return window['go']['types']['Appearance']['Orig'](); | ||
} | ||
|
||
export function String() { | ||
return window['go']['types']['Appearance']['String'](); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters