Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/utils/json/json.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package json

import "maps"

Check failure on line 3 in internal/utils/json/json.go

View workflow job for this annotation

GitHub Actions / Lint

File is not properly formatted (goimports)

Check failure on line 3 in internal/utils/json/json.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

File is not properly formatted (goimports)

import "encoding/json"

func Merge(json1, json2 []byte) ([]byte, error) {
Expand All @@ -14,9 +16,7 @@
}

// Merge map2 into map1
for key, value := range map2 {
map1[key] = value
}
maps.Copy(map1, map2)

// Marshal the merged result back into JSON
return json.Marshal(map1)
Expand Down
6 changes: 3 additions & 3 deletions merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ func TestTimelockProposal_Merge(t *testing.T) {
},
{
name: "success: merge salt",
proposal1: mustBuild(t, baseProposalBuilder().SetSalt(pointerTo(common.HexToHash("0x0123456789abcdef")))),
proposal2: mustBuild(t, baseProposalBuilder().SetSalt(pointerTo(common.HexToHash("0x9876543210fedcba")))),
proposal1: mustBuild(t, baseProposalBuilder().SetSalt(new(common.HexToHash("0x0123456789abcdef")))),
proposal2: mustBuild(t, baseProposalBuilder().SetSalt(new(common.HexToHash("0x9876543210fedcba")))),
assert: func(t *testing.T, merged *TimelockProposal) {
t.Helper()
want := pointerTo(common.HexToHash("0x9955115599551155"))
want := new(common.HexToHash("0x9955115599551155"))
require.Equal(t, want, merged.SaltOverride)
},
},
Expand Down
12 changes: 6 additions & 6 deletions sdk/aptos/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ func TestExecutor_ExecuteOperation(t *testing.T) {
mcms.EXPECT().MCMSExecutor().Return(mockMCMSExecutorModule)
mockMCMSExecutorModule.EXPECT().StageData(
&bind.TransactOpts{
SequenceNumber: pointerTo(uint64(789)),
SequenceNumber: new(uint64(789)),
Signer: signer,
},
generateData(50_000),
mock.Anything,
).Return(&api.PendingTransaction{Hash: "0xdeadbeef1"}, nil)
mockMCMSExecutorModule.EXPECT().StageData(
&bind.TransactOpts{
SequenceNumber: pointerTo(uint64(790)),
SequenceNumber: new(uint64(790)),
Signer: signer,
},
generateData(50_000),
mock.Anything,
).Return(&api.PendingTransaction{Hash: "0xdeadbeef2"}, nil)
mockMCMSExecutorModule.EXPECT().StageDataAndExecute(
&bind.TransactOpts{
SequenceNumber: pointerTo(uint64(791)),
SequenceNumber: new(uint64(791)),
Signer: signer,
},
TimelockRoleProposer.Byte(),
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestExecutor_ExecuteOperation(t *testing.T) {
mcms.EXPECT().MCMSExecutor().Return(mockMCMSExecutorModule)
mockMCMSExecutorModule.EXPECT().StageData(
&bind.TransactOpts{
SequenceNumber: pointerTo(uint64(789)),
SequenceNumber: new(uint64(789)),
Signer: signer,
},
generateData(50_000),
Expand Down Expand Up @@ -354,15 +354,15 @@ func TestExecutor_ExecuteOperation(t *testing.T) {
mcms.EXPECT().MCMSExecutor().Return(mockMCMSExecutorModule)
mockMCMSExecutorModule.EXPECT().StageData(
&bind.TransactOpts{
SequenceNumber: pointerTo(uint64(789)),
SequenceNumber: new(uint64(789)),
Signer: signer,
},
generateData(50_000),
mock.Anything,
).Return(&api.PendingTransaction{Hash: "0xdeadbeef1"}, nil)
mockMCMSExecutorModule.EXPECT().StageDataAndExecute(
&bind.TransactOpts{
SequenceNumber: pointerTo(uint64(790)),
SequenceNumber: new(uint64(790)),
Signer: signer,
},
TimelockRoleBypasser.Byte(),
Expand Down
3 changes: 2 additions & 1 deletion sdk/aptos/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"github.com/aptos-labs/aptos-go-sdk"
)

//go:fix inline
func pointerTo[T any](v T) *T {

Check failure on line 8 in sdk/aptos/utils.go

View workflow job for this annotation

GitHub Actions / Lint

func pointerTo is unused (unused)

Check failure on line 8 in sdk/aptos/utils.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

func pointerTo is unused (unused)
return &v
return new(v)
}

func hexToAddress(address string) (aptos.AccountAddress, error) {
Expand Down
18 changes: 9 additions & 9 deletions sdk/evm/bindings/abigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,40 +365,40 @@ func replaceAnonymousStructs(contractName string, fileNode *ast.File) *ast.File
func writeAdditionalMethods(contractName string, logNames []string, abi abi.ABI, bs []byte) []byte {
// Write the ParseLog method
if len(logNames) > 0 {
var logSwitchBody string
var logSwitchBody strings.Builder
for _, logName := range logNames {
//nolint:perfsprint // allow fmt.Sprintf in loop
logSwitchBody += fmt.Sprintf(`case _%v.abi.Events["%v"].ID:
logSwitchBody.WriteString(fmt.Sprintf(`case _%v.abi.Events["%v"].ID:
return _%v.Parse%v(log)
`, contractName, logName, contractName, logName)
`, contractName, logName, contractName, logName))
}

bs = append(bs, []byte(fmt.Sprintf(`
bs = append(bs, fmt.Appendf(nil, `
func (_%v *%v) ParseLog(log types.Log) (AbigenLog, error) {
switch log.Topics[0] {
%v
default:
return nil, fmt.Errorf("abigen wrapper received unknown log topic: %%v", log.Topics[0])
}
}
`, contractName, contractName, logSwitchBody))...)
`, contractName, contractName, logSwitchBody.String())...)
}

// Write the Topic method
for _, logName := range logNames {
bs = append(bs, []byte(fmt.Sprintf(`
bs = append(bs, fmt.Appendf(nil, `
func (%v%v) Topic() common.Hash {
return common.HexToHash("%v")
}
`, contractName, logName, abi.Events[logName].ID.Hex()))...)
`, contractName, logName, abi.Events[logName].ID.Hex())...)
}

// Write the Address method to the bottom of the file
bs = append(bs, []byte(fmt.Sprintf(`
bs = append(bs, fmt.Appendf(nil, `
func (_%v *%v) Address() common.Address {
return _%v.address
}
`, contractName, contractName, contractName))...)
`, contractName, contractName, contractName)...)

return bs
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/evm/execution_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ func extractRevertReasonFromError(err error) revertReasonData {
if strings.Contains(errStr, revertPrefix) {
// Try to extract the plain string revert reason
// Format: "execution reverted: revert: <reason>" or "revert: <reason>"
revertIdx := strings.Index(errStr, revertPrefix)
if revertIdx != -1 {
_, after, ok := strings.Cut(errStr, revertPrefix)
if ok {
// Extract everything after "revert: "
reason := strings.TrimSpace(errStr[revertIdx+len(revertPrefix):])
reason := strings.TrimSpace(after)
if reason != "" {
return revertReasonData{
Decoded: reason,
Expand Down Expand Up @@ -710,8 +710,8 @@ func getUnderlyingRevertReason(
rawReason = revertData.Decoded
}
if rawReason == "" {
if idx := strings.Index(errStr, revertPrefix); idx != -1 {
rawReason = strings.TrimSpace(errStr[idx+len(revertPrefix):])
if _, after, ok := strings.Cut(errStr, revertPrefix); ok {
rawReason = strings.TrimSpace(after)
}
}
if rawReason == "" {
Expand Down
5 changes: 1 addition & 4 deletions sdk/solana/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ func chunkIndexes(numItems int, chunkSize int) [][2]int {
indexes := make([][2]int, 0)

for i := 0; i < numItems; i += chunkSize {
end := i + chunkSize
if end > numItems {
end = numItems
}
end := min(i+chunkSize, numItems)
indexes = append(indexes, [2]int{i, end})
}

Expand Down
5 changes: 3 additions & 2 deletions sdk/solana/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

result := &rpc.GetTransactionResult{
Slot: 1,
BlockTime: pointerTo(solana.UnixTimeSeconds(time.Now().Unix())),
BlockTime: new(solana.UnixTimeSeconds(time.Now().Unix())),
Transaction: &rpc.TransactionResultEnvelope{},
Meta: &rpc.TransactionMeta{},
Version: 1,
Expand Down Expand Up @@ -117,6 +117,7 @@
return e.result.Logs
}

//go:fix inline
func pointerTo[T any](v T) *T {

Check failure on line 121 in sdk/solana/simulator.go

View workflow job for this annotation

GitHub Actions / Lint

func pointerTo is unused (unused)

Check failure on line 121 in sdk/solana/simulator.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

func pointerTo is unused (unused)
return &v
return new(v)
}
9 changes: 5 additions & 4 deletions sdk/solana/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func mockSolanaTransaction(
*result = &rpc.GetSignatureStatusesResult{
Value: []*rpc.SignatureStatusesResult{{
Slot: slot,
Confirmations: ptrTo(uint64(2)),
Confirmations: new(uint64(2)),
ConfirmationStatus: rpc.ConfirmationStatusConfirmed,
}},
}
Expand All @@ -181,7 +181,7 @@ func mockSolanaTransaction(
require.NoError(t, err)

if blockTime == nil {
blockTime = ptrTo(solana.UnixTimeSeconds(time.Now().Unix()))
blockTime = new(solana.UnixTimeSeconds(time.Now().Unix()))
}

*result = &rpc.GetTransactionResult{
Expand Down Expand Up @@ -284,7 +284,7 @@ func generateSignatures(t *testing.T, numSignatures int) []types.Signature {

signatures := make([]types.Signature, numSignatures)
for i := range signatures {
payload := []byte(fmt.Sprintf("\x19Ethereum Signed Message:\n320x%d", i))
payload := fmt.Appendf(nil, "\x19Ethereum Signed Message:\n320x%d", i)
hash := crypto.Keccak256Hash(payload)

sigBytes, err := crypto.Sign(hash[:], privateKey)
Expand All @@ -299,4 +299,5 @@ func generateSignatures(t *testing.T, numSignatures int) []types.Signature {
return signatures
}

func ptrTo[T any](value T) *T { return &value }
//go:fix inline
func ptrTo[T any](value T) *T { return new(value) }
4 changes: 2 additions & 2 deletions sdk/usbwallet/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction
err error
)
if chainID == nil {
if txrlp, err = rlp.EncodeToBytes([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}); err != nil {
if txrlp, err = rlp.EncodeToBytes([]any{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}); err != nil {
return common.Address{}, nil, err
}
} else {
if txrlp, err = rlp.EncodeToBytes([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), chainID, big.NewInt(0), big.NewInt(0)}); err != nil {
if txrlp, err = rlp.EncodeToBytes([]any{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), chainID, big.NewInt(0), big.NewInt(0)}); err != nil {
return common.Address{}, nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (w *wallet) selfDerive() {

context = context.Background() // TODO fix once CLD change with core.CtxProvider is in.
)
for i := 0; i < len(nextAddrs); i++ {
for i := range nextAddrs {
for empty := false; !empty; {
// Retrieve the next derived Ethereum account
if nextAddrs[i] == (common.Address{}) {
Expand Down
5 changes: 2 additions & 3 deletions timelock_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -188,9 +189,7 @@ func (m *TimelockProposal) Convert(

// 4) Rebuild chainMetadata in baseProposal
chainMetadataMap := make(map[types.ChainSelector]types.ChainMetadata)
for chain, metadata := range m.ChainMetadata {
chainMetadataMap[chain] = metadata
}
maps.Copy(chainMetadataMap, m.ChainMetadata)
baseProposal.ChainMetadata = chainMetadataMap

// 5) We’ll build the final MCMS-only proposal
Expand Down
3 changes: 2 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
return p, nil
}

//go:fix inline
func pointerTo[T any](v T) *T {

Check failure on line 89 in utils.go

View workflow job for this annotation

GitHub Actions / Lint

func pointerTo is unused (unused)

Check failure on line 89 in utils.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

func pointerTo is unused (unused)
return &v
return new(v)
}
Loading