Skip to content

Commit

Permalink
add: Support batch call by multicall only and mixing with native coin
Browse files Browse the repository at this point in the history
  • Loading branch information
Himitsuko committed Dec 22, 2022
1 parent f864dc6 commit b57e324
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 6 deletions.
138 changes: 132 additions & 6 deletions core/balance_scanner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions core/balance_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,85 @@ func TestBalanceScanner_BatchCall(t *testing.T) {
}
fmt.Println("Total result", resultCount)
}

func TestBalanceScanner_MultiBatchCall(t *testing.T) {
client, _ := ethclient.Dial("https://bsc-dataseed.binance.org/")
r, _ := rpc.Dial("https://bsc-dataseed.binance.org/")
bep20, _ := NewBalanceScanner("0xcA11bde05977b3631167028862bE2a173976CA11", client, r)
resultCount := 0
ret, err := bep20.BatchCallBalancesWithNative(common.HexToAddress("0xca0C80122afA57c38BcAa14fC77E056b94288469"), [][]common.Address{
{
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
},
{
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
},
{
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x0000000000000000000000000000000000000000"),
},
}, "0x0000000000000000000000000000000000000000")
if err != nil {
fmt.Println(err)
}
for j := 0; j < len(ret); j++ {
if j == len(ret)-1 {
assert.Equal(t, ret[j].String(), "207924141787718960")
} else {
assert.Equal(t, ret[j].String(), "1081707507519149458")
}
resultCount++
}
fmt.Println("Total result", resultCount)
}

func TestBalanceScanner_MultiBatchCallERC20Only(t *testing.T) {
client, _ := ethclient.Dial("https://bsc-dataseed.binance.org/")
r, _ := rpc.Dial("https://bsc-dataseed.binance.org/")
bep20, _ := NewBalanceScanner("0xcA11bde05977b3631167028862bE2a173976CA11", client, r)
resultCount := 0
ret, err := bep20.BatchCallBalancesWithNative(common.HexToAddress("0xca0C80122afA57c38BcAa14fC77E056b94288469"), [][]common.Address{
{
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
common.HexToAddress("0x7d99eda556388Ad7743A1B658b9C4FC67D7A9d74"),
},
}, "")
if err != nil {
fmt.Println(err)
}
for j := 0; j < len(ret); j++ {
assert.Equal(t, ret[j].String(), "1081707507519149458")
resultCount++
}
fmt.Println("Total result", resultCount)
}

func TestBalanceScanner_MultiBatchCallNativeOnly(t *testing.T) {
client, _ := ethclient.Dial("https://bsc-dataseed.binance.org/")
r, _ := rpc.Dial("https://bsc-dataseed.binance.org/")
bep20, _ := NewBalanceScanner("0xcA11bde05977b3631167028862bE2a173976CA11", client, r)
resultCount := 0
ret, err := bep20.BatchCallBalancesWithNative(common.HexToAddress("0xca0C80122afA57c38BcAa14fC77E056b94288469"), [][]common.Address{
{
common.HexToAddress("0x0000000000000000000000000000000000000000"),
},
}, "0x0000000000000000000000000000000000000000")
if err != nil {
fmt.Println(err)
}
for j := 0; j < len(ret); j++ {
assert.Equal(t, ret[j].String(), "207924141787718960")
resultCount++
}
fmt.Println("Total result", resultCount)
}

0 comments on commit b57e324

Please sign in to comment.