-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_util.go
36 lines (31 loc) · 1.03 KB
/
reader_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package djtx
import (
"math/big"
"github.com/lasthyphen/ortelius/models"
)
func addAssetInfoMap(assets map[models.StringID]models.AssetInfo, assets2 map[models.StringID]models.AssetInfo) map[models.StringID]models.AssetInfo {
addStringsFunc := func(t string, f string) string {
tbi := new(big.Int)
tbi.SetString(t, 10)
fbi := new(big.Int)
fbi.SetString(f, 10)
rbi := new(big.Int)
return rbi.Add(tbi, fbi).String()
}
addAssetInfos := func(t models.AssetInfo, f models.AssetInfo) models.AssetInfo {
t.TransactionCount += f.TransactionCount
t.UTXOCount += t.UTXOCount
t.Balance = models.TokenAmount(addStringsFunc(string(t.Balance), string(f.Balance)))
t.TotalReceived = models.TokenAmount(addStringsFunc(string(t.TotalReceived), string(f.TotalReceived)))
t.TotalSent = models.TokenAmount(addStringsFunc(string(t.TotalSent), string(f.TotalSent)))
return t
}
for k, v := range assets2 {
if assetInfo, ok := assets[k]; ok {
assets[k] = addAssetInfos(assetInfo, v)
} else {
assets[k] = v
}
}
return assets
}