refactor: move abis to system_init

* closes #31
This commit is contained in:
Mohamed Sohail 2022-12-01 13:07:22 +00:00
parent dbfe3e95c8
commit 4b180ea285
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
4 changed files with 12 additions and 12 deletions

View File

@ -13,6 +13,7 @@ import (
func initSystemContainer() *tasker.SystemContainer { func initSystemContainer() *tasker.SystemContainer {
return &tasker.SystemContainer{ return &tasker.SystemContainer{
Abis: initAbis(),
GasRefillThreshold: big.NewInt(ko.MustInt64("system.gas_refill_threshold")), GasRefillThreshold: big.NewInt(ko.MustInt64("system.gas_refill_threshold")),
GasRefillValue: big.NewInt(ko.MustInt64("system.gas_refill_value")), GasRefillValue: big.NewInt(ko.MustInt64("system.gas_refill_value")),
GiftableGasValue: big.NewInt(ko.MustInt64("system.giftable_gas_value")), GiftableGasValue: big.NewInt(ko.MustInt64("system.giftable_gas_value")),
@ -27,6 +28,13 @@ func initSystemContainer() *tasker.SystemContainer {
} }
} }
func initAbis() map[string]*w3.Func {
return map[string]*w3.Func{
"mint": w3.MustNewFunc("mint(address,uint256)", ""),
"transfer": w3.MustNewFunc("transfer(address,uint256)", "bool"),
}
}
func initSystemKey() *ecdsa.PrivateKey { func initSystemKey() *ecdsa.PrivateKey {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()

View File

@ -147,12 +147,7 @@ func GiftTokenProcessor(
return err return err
} }
abi, err := w3.NewFunc("mint(address,uint256)", "") input, err := system.Abis["mint"].EncodeArgs(publicKey, system.GiftableTokenValue)
if err != nil {
return err
}
input, err := abi.EncodeArgs(publicKey, system.GiftableTokenValue)
if err != nil { if err != nil {
return fmt.Errorf("ABI encode failed %v: %w", err, asynq.SkipRetry) return fmt.Errorf("ABI encode failed %v: %w", err, asynq.SkipRetry)
} }

View File

@ -55,12 +55,7 @@ func TransferToken(
return err return err
} }
abi, err := w3.NewFunc("transfer(address,uint256)", "bool") input, err := system.Abis["transfer"].EncodeArgs(w3.A(p.To), parseTransferValue(p.Amount, system.TokenDecimals))
if err != nil {
return err
}
input, err := abi.EncodeArgs(w3.A(p.To), parseTransferValue(p.Amount, system.TokenDecimals))
if err != nil { if err != nil {
return fmt.Errorf("ABI encode failed %v: %w", err, asynq.SkipRetry) return fmt.Errorf("ABI encode failed %v: %w", err, asynq.SkipRetry)
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/celo-org/celo-blockchain/common" "github.com/celo-org/celo-blockchain/common"
"github.com/grassrootseconomics/w3-celo-patch"
) )
type ( type (
@ -15,6 +16,7 @@ type (
) )
type SystemContainer struct { type SystemContainer struct {
Abis map[string]*w3.Func
GasRefillThreshold *big.Int GasRefillThreshold *big.Int
GasRefillValue *big.Int GasRefillValue *big.Int
GiftableGasValue *big.Int GiftableGasValue *big.Int