Skip to content

Commit

Permalink
chore: go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
renlulu committed Apr 16, 2024
1 parent c9bffe6 commit af0c9b6
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 69 deletions.
15 changes: 13 additions & 2 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ func (r *AvsRegistryChainReader) GetCheckSignaturesIndices(
nonSignerOperatorIdsBytes,
)
if err != nil {
return opstateretriever.OperatorStateRetrieverCheckSignaturesIndices{}, utils.WrapError("Failed to get check signatures indices", err)
return opstateretriever.OperatorStateRetrieverCheckSignaturesIndices{}, utils.WrapError(
"Failed to get check signatures indices",
err,
)
}
return checkSignatureIndices, nil
}
Expand Down Expand Up @@ -399,7 +402,15 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(
if err != nil {
return nil, nil, utils.WrapError("Cannot filter logs", err)
}
r.logger.Debug("avsRegistryChainReader.QueryExistingRegisteredOperatorPubKeys", "transactionLogs", logs, "fromBlock", i, "toBlock", toBlock)
r.logger.Debug(
"avsRegistryChainReader.QueryExistingRegisteredOperatorPubKeys",
"transactionLogs",
logs,
"fromBlock",
i,
"toBlock",
toBlock,
)

for _, vLog := range logs {

Expand Down
50 changes: 44 additions & 6 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,15 @@ func (w *AvsRegistryChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordina
socket string,
) (*gethtypes.Receipt, error) {
operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey)
w.logger.Info("registering operator with the AVS's registry coordinator", "avs-service-manager", w.serviceManagerAddr, "operator", operatorAddr, "quorumNumbers", quorumNumbers)
w.logger.Info(
"registering operator with the AVS's registry coordinator",
"avs-service-manager",
w.serviceManagerAddr,
"operator",
operatorAddr,
"quorumNumbers",
quorumNumbers,
)
// params to register bls pubkey with bls apk registry
g1HashedMsgToSign, err := w.registryCoordinator.PubkeyRegistrationMessageHash(&bind.CallOpts{}, operatorAddr)
if err != nil {
Expand Down Expand Up @@ -256,7 +264,17 @@ func (w *AvsRegistryChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordina
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info("successfully registered operator with AVS registry coordinator", "txHash", receipt.TxHash.String(), "avs-service-manager", w.serviceManagerAddr, "operator", operatorAddr, "quorumNumbers", quorumNumbers)
w.logger.Info(
"successfully registered operator with AVS registry coordinator",
"txHash",
receipt.TxHash.String(),
"avs-service-manager",
w.serviceManagerAddr,
"operator",
operatorAddr,
"quorumNumbers",
quorumNumbers,
)
return receipt, nil
}

Expand All @@ -270,15 +288,25 @@ func (w *AvsRegistryChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.UpdateOperatorsForQuorum(noSendTxOpts, operatorsPerQuorum, quorumNumbers.UnderlyingType())
tx, err := w.registryCoordinator.UpdateOperatorsForQuorum(
noSendTxOpts,
operatorsPerQuorum,
quorumNumbers.UnderlyingType(),
)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info("succesfully updated stakes for entire operator set", "txHash", receipt.TxHash.String(), "quorumNumbers", quorumNumbers)
w.logger.Info(
"succesfully updated stakes for entire operator set",
"txHash",
receipt.TxHash.String(),
"quorumNumbers",
quorumNumbers,
)
return receipt, nil

}
Expand All @@ -300,7 +328,13 @@ func (w *AvsRegistryChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info("succesfully updated stakes of operator subset for all quorums", "txHash", receipt.TxHash.String(), "operators", operators)
w.logger.Info(
"succesfully updated stakes of operator subset for all quorums",
"txHash",
receipt.TxHash.String(),
"operators",
operators,
)
return receipt, nil

}
Expand All @@ -323,6 +357,10 @@ func (w *AvsRegistryChainWriter) DeregisterOperator(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info("succesfully deregistered operator with the AVS's registry coordinator", "txHash", receipt.TxHash.String())
w.logger.Info(
"succesfully deregistered operator with the AVS's registry coordinator",
"txHash",
receipt.TxHash.String(),
)
return receipt, nil
}
16 changes: 14 additions & 2 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ func (w *ELChainWriter) UpdateOperatorDetails(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info("succesfully updated operator metadata URI", "txHash", receipt.TxHash.String(), "operator", operator.Address)
w.logger.Info(
"succesfully updated operator metadata URI",
"txHash",
receipt.TxHash.String(),
"operator",
operator.Address,
)

tx, err = w.delegationManager.UpdateOperatorMetadataURI(noSendTxOpts, operator.MetadataUrl)
if err != nil {
Expand All @@ -171,7 +177,13 @@ func (w *ELChainWriter) UpdateOperatorDetails(
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info("succesfully updated operator details", "txHash", receipt.TxHash.String(), "operator", operator.Address)
w.logger.Info(
"succesfully updated operator details",
"txHash",
receipt.TxHash.String(),
"operator",
operator.Address,
)
return receipt, nil
}

Expand Down
24 changes: 19 additions & 5 deletions chainio/clients/fireblocks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type Client interface {
CancelTransaction(ctx context.Context, txID string) (bool, error)
// ListContracts makes a ListContracts request to the Fireblocks API
// It returns a list of whitelisted contracts and their assets for the account.
// This call is used to get the contract ID for a whitelisted contract, which is needed as destination account ID by NewContractCallRequest in a ContractCall
// This call is used to get the contract ID for a whitelisted contract, which is needed as destination account ID by
// NewContractCallRequest in a ContractCall
// ref: https://developers.fireblocks.com/reference/get_contracts
ListContracts(ctx context.Context) ([]WhitelistedContract, error)
// ListVaultAccounts makes a ListVaultAccounts request to the Fireblocks API
Expand Down Expand Up @@ -72,7 +73,13 @@ type ErrorResponse struct {
Code int `json:"code"`
}

func NewClient(apiKey string, secretKey []byte, baseURL string, timeout time.Duration, logger logging.Logger) (Client, error) {
func NewClient(
apiKey string,
secretKey []byte,
baseURL string,
timeout time.Duration,
logger logging.Logger,
) (Client, error) {
c := http.Client{Timeout: timeout}
privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(secretKey)
if err != nil {
Expand All @@ -90,7 +97,8 @@ func NewClient(apiKey string, secretKey []byte, baseURL string, timeout time.Dur
}

// signJwt signs a JWT token for the Fireblocks API
// mostly copied from the Fireblocks example: https://github.com/fireblocks/developers-hub/blob/main/authentication_examples/go/test.go
// mostly copied from the Fireblocks example:
// https://github.com/fireblocks/developers-hub/blob/main/authentication_examples/go/test.go
func (f *client) signJwt(path string, bodyJson interface{}, durationSeconds int64) (string, error) {
nonce := uuid.New().String()
now := time.Now().Unix()
Expand Down Expand Up @@ -124,7 +132,8 @@ func (f *client) signJwt(path string, bodyJson interface{}, durationSeconds int6
}

// makeRequest makes a request to the Fireblocks API
// mostly copied from the Fireblocks example: https://github.com/fireblocks/developers-hub/blob/main/authentication_examples/go/test.go
// mostly copied from the Fireblocks example:
// https://github.com/fireblocks/developers-hub/blob/main/authentication_examples/go/test.go
func (f *client) makeRequest(ctx context.Context, method, path string, body interface{}) ([]byte, error) {
// remove query parameters from path and join with baseURL
pathURI, err := url.Parse(path)
Expand Down Expand Up @@ -187,7 +196,12 @@ func (f *client) makeRequest(ctx context.Context, method, path string, body inte
if err != nil {
return nil, fmt.Errorf("error parsing error response: %w", err)
}
return nil, fmt.Errorf("error response (%d) from Fireblocks with code %d: %s", resp.StatusCode, errResp.Code, errResp.Message)
return nil, fmt.Errorf(
"error response (%d) from Fireblocks with code %d: %s",
resp.StatusCode,
errResp.Code,
errResp.Message,
)
}

return respBody, nil
Expand Down
6 changes: 4 additions & 2 deletions chainio/clients/fireblocks/contract_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ type ContractCallRequest struct {
Amount string `json:"amount,omitempty"`
ExtraParameters extraParams `json:"extraParameters"`
// In case a transaction is stuck, specify the hash of the stuck transaction to replace it
// by this transaction with a higher fee, or to replace it with this transaction with a zero fee and drop it from the blockchain.
// by this transaction with a higher fee, or to replace it with this transaction with a zero fee and drop it from
// the blockchain.
ReplaceTxByHash string `json:"replaceTxByHash,omitempty"`
// GasPrice and GasLimit are the gas price and gas limit for the transaction.
// If GasPrice is specified (non-1559), MaxFee and PriorityFee are not required.
GasPrice string `json:"gasPrice,omitempty"`
GasLimit string `json:"gasLimit,omitempty"`
// MaxFee and PriorityFee are the maximum and priority fees for the transaction.
// If the transaction is stuck, the Fireblocks platform will replace the transaction with a new one with a higher fee.
// If the transaction is stuck, the Fireblocks platform will replace the transaction with a new one with a higher
// fee.
// These fields are required if FeeLevel is not specified.
MaxFee string `json:"maxFee,omitempty"`
PriorityFee string `json:"priorityFee,omitempty"`
Expand Down
31 changes: 25 additions & 6 deletions chainio/clients/wallet/fireblocks_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ var _ Wallet = (*fireblocksWallet)(nil)

var (
// ErrNotYetBroadcasted indicates that the transaction has not been broadcasted yet.
// This can happen if the transaction is still being processed by Fireblocks and has not been broadcasted to the blockchain yet.
// This can happen if the transaction is still being processed by Fireblocks and has not been broadcasted to the
// blockchain yet.
ErrNotYetBroadcasted = errors.New("transaction not yet broadcasted")
// ErrReceiptNotYetAvailable indicates that the transaction has been broadcasted but has not been confirmed onchain yet.
// ErrReceiptNotYetAvailable indicates that the transaction has been broadcasted but has not been confirmed onchain
// yet.
ErrReceiptNotYetAvailable = errors.New("transaction receipt not yet available")
ErrTransactionFailed = errors.New("transaction failed")
)
Expand All @@ -51,7 +53,12 @@ type fireblocksWallet struct {
whitelistedContracts map[common.Address]*fireblocks.WhitelistedContract
}

func NewFireblocksWallet(fireblocksClient fireblocks.Client, ethClient eth.Client, vaultAccountName string, logger logging.Logger) (Wallet, error) {
func NewFireblocksWallet(
fireblocksClient fireblocks.Client,
ethClient eth.Client,
vaultAccountName string,
logger logging.Logger,
) (Wallet, error) {
chainID, err := ethClient.ChainID(context.Background())
if err != nil {
return nil, fmt.Errorf("error getting chain ID: %w", err)
Expand Down Expand Up @@ -89,7 +96,10 @@ func (t *fireblocksWallet) getAccount(ctx context.Context) (*fireblocks.VaultAcc
return t.account, nil
}

func (t *fireblocksWallet) getWhitelistedContract(ctx context.Context, address common.Address) (*fireblocks.WhitelistedContract, error) {
func (t *fireblocksWallet) getWhitelistedContract(
ctx context.Context,
address common.Address,
) (*fireblocks.WhitelistedContract, error) {
assetID, ok := fireblocks.AssetIDByChain[t.chainID.Uint64()]
if !ok {
return nil, fmt.Errorf("unsupported chain %d", t.chainID.Uint64())
Expand Down Expand Up @@ -249,15 +259,24 @@ func (t *fireblocksWallet) GetTransactionReceipt(ctx context.Context, txID TxID)
return nil, fmt.Errorf("%w: the Fireblocks transaction %s is in status %s", ErrNotYetBroadcasted, txID, fireblockTx.Status)
}

return nil, fmt.Errorf("%w: the Fireblocks transaction %s is in status %s", ErrReceiptNotYetAvailable, txID, fireblockTx.Status)
return nil, fmt.Errorf(
"%w: the Fireblocks transaction %s is in status %s",
ErrReceiptNotYetAvailable,
txID,
fireblockTx.Status,
)
}

func (f *fireblocksWallet) SenderAddress(ctx context.Context) (common.Address, error) {
account, err := f.getAccount(ctx)
if err != nil {
return common.Address{}, fmt.Errorf("error getting account: %w", err)
}
addresses, err := f.fireblocksClient.GetAssetAddresses(ctx, account.ID, fireblocks.AssetIDByChain[f.chainID.Uint64()])
addresses, err := f.fireblocksClient.GetAssetAddresses(
ctx,
account.ID,
fireblocks.AssetIDByChain[f.chainID.Uint64()],
)
if err != nil {
return common.Address{}, fmt.Errorf("error getting asset addresses: %w", err)
}
Expand Down
14 changes: 8 additions & 6 deletions chainio/clients/wallet/fireblocks_wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,14 @@ func TestSenderAddress(t *testing.T) {
},
}, nil)
expectedSenderAddr := "0x0000000000000000000000000000000000000000"
fireblocksClient.EXPECT().GetAssetAddresses(gomock.Any(), "vaultAccountID", assetID).Return([]fireblocks.AssetAddress{
{
AssetID: assetID,
Address: expectedSenderAddr,
},
}, nil)
fireblocksClient.EXPECT().
GetAssetAddresses(gomock.Any(), "vaultAccountID", assetID).
Return([]fireblocks.AssetAddress{
{
AssetID: assetID,
Address: expectedSenderAddr,
},
}, nil)

addr, err := w.SenderAddress(context.Background())
assert.Nil(t, err)
Expand Down
7 changes: 6 additions & 1 deletion chainio/clients/wallet/privatekey_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ type privateKeyWallet struct {
contracts map[common.Address]*bind.BoundContract
}

func NewPrivateKeyWallet(ethClient eth.Client, signer signerv2.SignerFn, signerAddress common.Address, logger logging.Logger) (Wallet, error) {
func NewPrivateKeyWallet(
ethClient eth.Client,
signer signerv2.SignerFn,
signerAddress common.Address,
logger logging.Logger,
) (Wallet, error) {
return &privateKeyWallet{
ethClient: ethClient,
address: signerAddress,
Expand Down
Loading

0 comments on commit af0c9b6

Please sign in to comment.