Compare commits

...

5 Commits

Author SHA1 Message Date
Mohamed Sohail dbcc03d1e8
Update README.md 2022-08-09 15:02:00 +03:00
DeepSource Bot 5d2daa2c8e Add .deepsource.toml 2022-06-21 07:38:06 +00:00
Mohamed Sohail 2070f9afcd
Merge pull request #7 from grassrootseconomics/sohail/total-supply
add: (feat) erc20 total supply
2022-05-23 12:49:40 +03:00
Mohamed Sohail 9a7dc6457e
add: (feat) erc20 total supply 2022-05-23 12:47:10 +03:00
Mohamed Sohail a3052d9e21
fix: pointer param for provider 2022-05-18 13:41:55 +03:00
11 changed files with 36 additions and 22 deletions

8
.deepsource.toml Normal file
View File

@ -0,0 +1,8 @@
version = 1
[[analyzers]]
name = "go"
enabled = true
[analyzers.meta]
import_root = "github.com/grassrootseconomics/cic-go"

View File

@ -1,3 +1,5 @@
> DEPRECATED: Use https://github.com/grassrootseconomics/cic-go-sdk
[![Go Reference](https://pkg.go.dev/badge/github.com/grassrootseconomics/cic_go.svg)](https://pkg.go.dev/github.com/grassrootseconomics/cic_go) [![Go Reference](https://pkg.go.dev/badge/github.com/grassrootseconomics/cic_go.svg)](https://pkg.go.dev/github.com/grassrootseconomics/cic_go)
[![Go](https://github.com/grassrootseconomics/cic_go/actions/workflows/go.yml/badge.svg)](https://github.com/grassrootseconomics/cic_go/actions/workflows/go.yml) [![Go](https://github.com/grassrootseconomics/cic_go/actions/workflows/go.yml/badge.svg)](https://github.com/grassrootseconomics/cic_go/actions/workflows/go.yml)
[![Coverage Status](https://coveralls.io/repos/github/grassrootseconomics/cic_go/badge.svg?branch=sohail/cic_net_updates)](https://coveralls.io/github/grassrootseconomics/cic_go?branch=sohail/cic_net_updates) [![Coverage Status](https://coveralls.io/repos/github/grassrootseconomics/cic_go/badge.svg?branch=sohail/cic_net_updates)](https://coveralls.io/github/grassrootseconomics/cic_go?branch=sohail/cic_net_updates)
@ -22,4 +24,4 @@ import (
cic_meta "github.com/grassrootseconomics/cic-go/meta" cic_meta "github.com/grassrootseconomics/cic-go/meta"
cic_net "github.com/grassrootseconomics/cic-go/net" cic_net "github.com/grassrootseconomics/cic-go/net"
) )
``` ```

View File

@ -10,9 +10,9 @@ type BatchBalance struct {
batchContract common.Address batchContract common.Address
} }
func NewBatchBalance(rpcProvider provider.Provider, batchContract common.Address) (*BatchBalance, error) { func NewBatchBalance(rpcProvider *provider.Provider, batchContract common.Address) (*BatchBalance, error) {
return &BatchBalance{ return &BatchBalance{
provider: &rpcProvider, provider: rpcProvider,
batchContract: batchContract, batchContract: batchContract,
}, nil }, nil
} }

View File

@ -27,7 +27,7 @@ func TestBatchBalance_Connect(t *testing.T) {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
batchBalance, _ := NewBatchBalance(*newProvider, w3.A(conf.batchContract)) batchBalance, _ := NewBatchBalance(newProvider, w3.A(conf.batchContract))
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
if err := batchBalance.provider.EthClient.Close(); (err != nil) != wantErr { if err := batchBalance.provider.EthClient.Close(); (err != nil) != wantErr {

View File

@ -40,7 +40,7 @@ func TestBatchBalance_TokensBalance(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
batchBalance, err := NewBatchBalance(*newProvider, w3.A(conf.batchContract)) batchBalance, err := NewBatchBalance(newProvider, w3.A(conf.batchContract))
if err != nil { if err != nil {
t.Fatalf("NewBatchBalance error = %v", err) t.Fatalf("NewBatchBalance error = %v", err)

View File

@ -10,9 +10,9 @@ type CicNet struct {
tokenIndex common.Address tokenIndex common.Address
} }
func NewCicNet(rpcProvider provider.Provider, tokenIndex common.Address) (*CicNet, error) { func NewCicNet(rpcProvider *provider.Provider, tokenIndex common.Address) (*CicNet, error) {
return &CicNet{ return &CicNet{
provider: &rpcProvider, provider: rpcProvider,
tokenIndex: tokenIndex, tokenIndex: tokenIndex,
}, nil }, nil
} }

View File

@ -29,7 +29,7 @@ func TestCicNet_Connect(t *testing.T) {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, _ := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, _ := NewCicNet(newProvider, w3.A(conf.tokenIndex))
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
if err := cicnet.provider.EthClient.Close(); (err != nil) != wantErr { if err := cicnet.provider.EthClient.Close(); (err != nil) != wantErr {

View File

@ -50,7 +50,7 @@ func TestCicNet_DemurrageToken_DemurrageTokeInfo(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
if err != nil { if err != nil {
t.Fatalf("NewCicNet error = %v", err) t.Fatalf("NewCicNet error = %v", err)
@ -119,7 +119,7 @@ func TestCicNet_DemurrageToken_BaseBalanceOf(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
for _, testcase := range tests { for _, testcase := range tests {
tt := testcase tt := testcase
@ -161,7 +161,7 @@ func TestCicNet_DemurrageToken_ChangePeriod(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
nonce, err := cicnet.LastNonce(context.Background(), fromAddress) nonce, err := cicnet.LastNonce(context.Background(), fromAddress)
if err != nil { if err != nil {
@ -226,7 +226,7 @@ func TestCicNet_DemurrageToken_ApplyDemurrageLimited(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
nonce, err := cicnet.LastNonce(context.Background(), fromAddress) nonce, err := cicnet.LastNonce(context.Background(), fromAddress)
if err != nil { if err != nil {

View File

@ -10,9 +10,10 @@ import (
) )
type ERC20Token struct { type ERC20Token struct {
Name string Name string
Symbol string Symbol string
Decimals big.Int Decimals big.Int
TotalSupply big.Int
} }
func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address) (ERC20Token, error) { func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address) (ERC20Token, error) {
@ -20,6 +21,7 @@ func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address
tokenName string tokenName string
tokenSymbol string tokenSymbol string
tokenDecimals big.Int tokenDecimals big.Int
totalSupply big.Int
) )
err := c.provider.EthClient.CallCtx( err := c.provider.EthClient.CallCtx(
@ -27,15 +29,17 @@ func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address
eth.CallFunc(w3.MustNewFunc("name()", "string"), tokenAddress).Returns(&tokenName), eth.CallFunc(w3.MustNewFunc("name()", "string"), tokenAddress).Returns(&tokenName),
eth.CallFunc(w3.MustNewFunc("symbol()", "string"), tokenAddress).Returns(&tokenSymbol), eth.CallFunc(w3.MustNewFunc("symbol()", "string"), tokenAddress).Returns(&tokenSymbol),
eth.CallFunc(w3.MustNewFunc("decimals()", "uint256"), tokenAddress).Returns(&tokenDecimals), eth.CallFunc(w3.MustNewFunc("decimals()", "uint256"), tokenAddress).Returns(&tokenDecimals),
eth.CallFunc(w3.MustNewFunc("totalSupply()", "uint256"), tokenAddress).Returns(&totalSupply),
) )
if err != nil { if err != nil {
return ERC20Token{}, err return ERC20Token{}, err
} }
return ERC20Token{ return ERC20Token{
Name: tokenName, Name: tokenName,
Symbol: tokenSymbol, Symbol: tokenSymbol,
Decimals: tokenDecimals, Decimals: tokenDecimals,
TotalSupply: totalSupply,
}, nil }, nil
} }
func (c *CicNet) BalanceOf(ctx context.Context, tokenAddress common.Address, accountAddress common.Address) (big.Int, error) { func (c *CicNet) BalanceOf(ctx context.Context, tokenAddress common.Address, accountAddress common.Address) (big.Int, error) {

View File

@ -43,7 +43,7 @@ func TestCicNet_ERC20Token_ERC20TokenInfo(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
if err != nil { if err != nil {
t.Fatalf("NewCicNet error = %v", err) t.Fatalf("NewCicNet error = %v", err)
@ -102,7 +102,7 @@ func TestCicNet_ERC20Token_BalanceOf(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
for _, testcase := range tests { for _, testcase := range tests {
tt := testcase tt := testcase

View File

@ -17,7 +17,7 @@ func TestCicNet_TokenIndex_EntryCount(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
if err != nil { if err != nil {
t.Fatalf("NewCicNet error = %v", err) t.Fatalf("NewCicNet error = %v", err)
@ -69,7 +69,7 @@ func TestCicNet_TokenIndex_AddressAtIndex(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Creating an rpc instance failed = %v", err) t.Errorf("Creating an rpc instance failed = %v", err)
} }
cicnet, err := NewCicNet(*newProvider, w3.A(conf.tokenIndex)) cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
if err != nil { if err != nil {
t.Fatalf("NewCicNet error = %v", err) t.Fatalf("NewCicNet error = %v", err)