Skip to content

Commit

Permalink
update project pledge address check.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangjinyuan committed Nov 24, 2022
1 parent bdbf16c commit da84267
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
46 changes: 31 additions & 15 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ type coin struct {
}

type coinAddress struct {
Project string `json:"project"`
Address string `json:"address"`
Height string `json:"height"`
TokenAddress string `json:"tokenAddress"`
Balance string `json:"balance"`
Project string `json:"project"`
ProjectFullName string `json:"projectFullName"`
Address string `json:"address"`
TokenAddress string `json:"tokenAddress"`
}

func NewAddressBalanceValidator(coinJSONConfig string) (*AddressBalanceValidator, error) {
Expand Down Expand Up @@ -97,14 +96,17 @@ func (r *AddressBalanceValidator) loadCoinJSON(content []byte) error {
}
if len(value.WhiteList) > 0 {
for _, addr := range value.WhiteList {
key := fmt.Sprintf("%s:%s:%s", value.Name, addr.Address, addr.Height)
if addr.Project == "" || addr.Address == "" {
err = errors.New(fmt.Sprintf("%s not config the whitelist project/address filed", value.Name))
return err
}
if addr.ProjectFullName == "" {
addr.ProjectFullName = addr.Project
}
key := fmt.Sprintf("%s:%s", value.Name, addr.Address)
if _, exist := addressWhiteListMap[key]; !exist {
addressWhiteListMap[key] = addr
}
if addr.Project == "" || addr.Balance == "" || addr.Address == "" || addr.Height == "" {
err = errors.New(fmt.Sprintf("%s not config the whitelist project/address/height/balance filed", value.Name))
return err
}
}
}
}
Expand Down Expand Up @@ -135,9 +137,17 @@ func (r *AddressBalanceValidator) GetCoinAddressBalanceInfoByJSONFormat(address,
var defaultUnit string
if pConf.RPC.Enabled {
// get address balance from white list
key := fmt.Sprintf("%s:%s:%s", pConf.Name, address, height)
// the address in white list doesn't support node RPC query, if RPC config enable, return the balance in por data.
key := fmt.Sprintf("%s:%s", pConf.Name, address)
if _, exist := r.confCoinAddressWhiteListMap[key]; exist {
return r.confCoinAddressWhiteListMap[key].Balance, nil
log.Infof("notice: the address %s in project %s doesn't support node rpc method to query, "+
"if rpc config enable, return the balance in por data.", address, r.confCoinAddressWhiteListMap[key].ProjectFullName)
if _, exist = PorCoinDataMap[key]; exist {
result = PorCoinDataMap[key].Balance
} else {
result = "0"
}
return result, nil
}

var request *client.JsonRpcRequest
Expand Down Expand Up @@ -219,7 +229,8 @@ func (r *AddressBalanceValidator) GetCoinAddressBalanceInfoByJSONFormat(address,
}
var project, tokenAddress string
// get address coin name from white list
key := fmt.Sprintf("%s:%s:%s", pConf.Name, address, height)
// add request params
key := fmt.Sprintf("%s:%s", pConf.Name, address)
if _, exist := r.confCoinAddressWhiteListMap[key]; exist {
project = r.confCoinAddressWhiteListMap[key].Project
tokenAddress = r.confCoinAddressWhiteListMap[key].TokenAddress
Expand Down Expand Up @@ -334,9 +345,14 @@ func (r *AddressBalanceValidator) GetCoinAddressTotalBalance(coin, height string
for _, item := range items {
address := item.(string)
// ignore white list address
key := fmt.Sprintf("%s:%s:%s", pConf.Name, address, height)
key := fmt.Sprintf("%s:%s", pConf.Name, address)
if _, exist := r.confCoinAddressWhiteListMap[key]; exist {
balance := r.confCoinAddressWhiteListMap[key].Balance
log.Infof("notice: the address %s in project %s doesn't support node rpc method to query, "+
"if rpc config enable, return the balance in por data", address, r.confCoinAddressWhiteListMap[key].ProjectFullName)
balance := "0"
if _, exist = PorCoinDataMap[key]; exist {
balance = PorCoinDataMap[key].Balance
}
balanceInt, _ := big.NewInt(0).SetString(balance, 10)
totalBalance = totalBalance.Add(totalBalance, balanceInt)
continue
Expand Down
11 changes: 5 additions & 6 deletions docs/checkbalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ There is an rpc.json configuration file in the binary zip and in the source code

**Explanation**
1. When both RPC and API are configured, RPC is used for queries.
2. The snapshot file contains the USDT pledged to the Compound platform. Since the Node RPC does not support querying the USDT pledged to the Compound platform, when the USDT-ERC20 RPC configuration is enabled, the USDT balance pledged to the Compound platform is retrieved from the following configuration. You can use the [Compound API](https://api.compound.finance/api/v2/account?addresses%5B%5D=0xb99cc7e10fe0acc68c50c7829f473d81e23249cc&block_number=16023042) to verify this.
2. The snapshot file contains the USDT pledged to the Compound platform, the configuration is as follows. Since the Node RPC does not support querying the USDT pledged to the Compound platform, when the USDT-ERC20 RPC configuration is enabled, the USDT balance pledged to the Compound platform is retrieved from the snapshot data. You can use the [Compound API](https://api.compound.finance/api/v2/account?addresses%5B%5D=0xb99cc7e10fe0acc68c50c7829f473d81e23249cc&block_number=16023042) to verify this.

```text
{
Expand All @@ -60,11 +60,10 @@ There is an rpc.json configuration file in the binary zip and in the source code
"rpc": { ... },
"whiteList": [
{
"project": "comp",
"address": "0xb99cc7e10fe0acc68c50c7829f473d81e23249cc",
"height": "16023042",
"tokenAddress": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9",
"balance": "10664614958377"
"project": "comp",
"projectFullName": "compound",
"address": "0xb99cc7e10fe0acc68c50c7829f473d81e23249cc",
"tokenAddress": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9"
}
]
}
Expand Down
11 changes: 5 additions & 6 deletions docs/checkbalance_zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ API、token合约地址等信息,以便我们的工具可以查询链上余额

**说明**
1. 当同时配置RPC和API时,会使用RPC进行查询。
2. 快照文件包含质押在Compound平台的USDT,由于节点不支持查询质押在Compound平台的USDT,当USDT-ERC20 RPC配置开启时,会从以下配置中获取质押在Compound平台上的USDT余额。您可以使用[Compound API](https://api.compound.finance/api/v2/account?addresses%5B%5D=0xb99cc7e10fe0acc68c50c7829f473d81e23249cc&block_number=16023042)进行验证。
2. 快照文件包含质押在Compound平台的USDT,相关配置如下。由于节点不支持查询质押在Compound平台的USDT,当USDT-ERC20 RPC配置开启时,会从快照数据中获取质押在Compound平台上的USDT余额, 您可以使用[Compound API](https://api.compound.finance/api/v2/account?addresses%5B%5D=0xb99cc7e10fe0acc68c50c7829f473d81e23249cc&block_number=16023042)进行验证。

```text
{
Expand All @@ -62,11 +62,10 @@ API、token合约地址等信息,以便我们的工具可以查询链上余额
"rpc": { ... },
"whiteList": [
{
"project": "comp",
"address": "0xb99cc7e10fe0acc68c50c7829f473d81e23249cc",
"height": "16023042",
"tokenAddress": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9",
"balance": "10664614958377"
"project": "comp",
"projectFullName": "compound",
"address": "0xb99cc7e10fe0acc68c50c7829f473d81e23249cc",
"tokenAddress": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9"
}
]
}
Expand Down
5 changes: 2 additions & 3 deletions example/rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@
"whiteList": [
{
"project": "comp",
"projectFullName": "compound",
"address": "0xb99cc7e10fe0acc68c50c7829f473d81e23249cc",
"height": "16023042",
"tokenAddress": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9",
"balance": "10664614958377"
"tokenAddress": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9"
}
]
},
Expand Down

0 comments on commit da84267

Please sign in to comment.