mirror of
https://github.com/alexgo-io/libbrc20-indexer.git
synced 2026-04-30 12:42:01 +08:00
feat: support testnet
This commit is contained in:
@@ -11,9 +11,11 @@ import (
|
||||
var (
|
||||
inputfile string
|
||||
outputfile string
|
||||
testnet bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&testnet, "testnet", false, "testnet")
|
||||
flag.StringVar(&inputfile, "input", "./data/brc20.input.txt", "the filename of input data, default(./data/brc20.input.txt)")
|
||||
flag.StringVar(&outputfile, "output", "./data/brc20.output.txt", "the filename of output result, default(./data/brc20.output.txt)")
|
||||
|
||||
@@ -33,5 +35,6 @@ func main() {
|
||||
g.InscriptionsTickerInfoMap,
|
||||
g.UserTokensBalanceData,
|
||||
g.TokenUsersBalanceData,
|
||||
testnet,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func LoadBRC20InputData(fname string) ([]*model.InscriptionBRC20Data, error) {
|
||||
|
||||
var brc20Datas []*model.InscriptionBRC20Data
|
||||
scanner := bufio.NewScanner(file)
|
||||
max := 4 * 1024 * 1024
|
||||
max := 128 * 1024 * 1024
|
||||
buf := make([]byte, max)
|
||||
scanner.Buffer(buf, max)
|
||||
|
||||
@@ -143,8 +143,14 @@ func DumpTickerInfoMap(fname string,
|
||||
inscriptionsTickerInfoMap map[string]*model.BRC20TokenInfo,
|
||||
userTokensBalanceData map[string]map[string]*model.BRC20TokenBalance,
|
||||
tokenUsersBalanceData map[string]map[string]*model.BRC20TokenBalance,
|
||||
testnet bool,
|
||||
) {
|
||||
|
||||
netParams := &chaincfg.MainNetParams
|
||||
if testnet {
|
||||
netParams = &chaincfg.TestNet3Params
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
|
||||
if err != nil {
|
||||
log.Fatalf("open block index file failed, %s", err)
|
||||
@@ -183,12 +189,12 @@ func DumpTickerInfoMap(fname string,
|
||||
continue
|
||||
}
|
||||
|
||||
addressFrom, err := utils.GetAddressFromScript([]byte(h.PkScriptFrom), &chaincfg.MainNetParams)
|
||||
addressFrom, err := utils.GetAddressFromScript([]byte(h.PkScriptFrom), netParams)
|
||||
if err != nil {
|
||||
addressFrom = hex.EncodeToString([]byte(h.PkScriptFrom))
|
||||
}
|
||||
|
||||
addressTo, err := utils.GetAddressFromScript([]byte(h.PkScriptTo), &chaincfg.MainNetParams)
|
||||
addressTo, err := utils.GetAddressFromScript([]byte(h.PkScriptTo), netParams)
|
||||
if err != nil {
|
||||
addressTo = hex.EncodeToString([]byte(h.PkScriptTo))
|
||||
}
|
||||
@@ -216,7 +222,7 @@ func DumpTickerInfoMap(fname string,
|
||||
for _, holder := range allHolders {
|
||||
balanceData := tokenUsersBalanceData[ticker][holder]
|
||||
|
||||
address, err := utils.GetAddressFromScript([]byte(balanceData.PkScript), &chaincfg.MainNetParams)
|
||||
address, err := utils.GetAddressFromScript([]byte(balanceData.PkScript), netParams)
|
||||
if err != nil {
|
||||
address = hex.EncodeToString([]byte(balanceData.PkScript))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user