Skip to content

Commit

Permalink
Support wallet nicknames
Browse files Browse the repository at this point in the history
  • Loading branch information
jtolio committed Feb 20, 2024
1 parent e2175e2 commit 1d41e7e
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cmd_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func (cmd *cmdConfirm) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
printTransactionStatus(ctx, transactor.Caller, cmd.transactionID)
printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, cmd.transactionID)
return nil
}
2 changes: 1 addition & 1 deletion cmd_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func (cmd *cmdExecute) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, cmd.transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, cmd.transactionID)
}
2 changes: 1 addition & 1 deletion cmd_query_multisig_transaction_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (cmd *cmdQueryMultiSigTransactionList) Execute(ctx context.Context) error {
if needsSeparator {
fmt.Fprintln(clingy.Stdout(ctx))
}
if err := printTransactionStatus(ctx, caller, transactionID); err != nil {
if err := printTransactionStatus(ctx, cmd.caller.client.nicknames, caller, transactionID); err != nil {
return err
}
needsSeparator = true
Expand Down
2 changes: 1 addition & 1 deletion cmd_query_multisig_transaction_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ func (cmd *cmdQueryMultiSigTransactionStatus) Execute(ctx context.Context) error
if err != nil {
return err
}
return printTransactionStatus(ctx, caller, cmd.transactionID)
return printTransactionStatus(ctx, cmd.caller.client.nicknames, caller, cmd.transactionID)
}
2 changes: 1 addition & 1 deletion cmd_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func (cmd *cmdRevoke) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, cmd.transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, cmd.transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (cmd *cmdSubmitContractCall) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}

func loadABI(path string) (*abi.ABI, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd_submit_eth_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func (cmd *cmdSubmitETHTransfer) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_multisig_owner_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func (cmd *cmdSubmitMultisigOwnerAdd) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_multisig_owner_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func (cmd *cmdSubmitMultisigOwnerRemove) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_multisig_owner_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func (cmd *cmdSubmitMultisigOwnerReplace) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_multisig_requirement_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func (cmd *cmdSubmitMultisigRequirementChange) Execute(ctx context.Context) erro
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_token_approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (cmd *cmdSubmitTokenApprove) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_token_set_upgrade_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func (cmd *cmdSubmitTokenSetUpgradeMaster) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_token_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (cmd *cmdSubmitTokenTransfer) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_submit_token_transfer_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ func (cmd *cmdSubmitTokenTransferFrom) Execute(ctx context.Context) error {
}

fmt.Fprintln(clingy.Stdout(ctx))
return printTransactionStatus(ctx, transactor.Caller, transactionID)
return printTransactionStatus(ctx, cmd.transactor.client.nicknames, transactor.Caller, transactionID)
}
2 changes: 1 addition & 1 deletion cmd_test_deploy_multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (cmd *cmdTestDeployMultiSig) Execute(ctx context.Context) error {
if err != nil {
return err
}
opts, done, err := cmd.sender.transactOpts(ctx, client)
opts, done, err := cmd.sender.transactOpts(ctx, cmd.client.nicknames, client)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd_test_deploy_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (cmd *cmdTestDeployToken) Execute(ctx context.Context) error {
if err != nil {
return err
}
opts, done, err := cmd.sender.transactOpts(ctx, client)
opts, done, err := cmd.sender.transactOpts(ctx, cmd.client.nicknames, client)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd_test_eth_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (cmd *cmdTestETHTransfer) Execute(ctx context.Context) error {
if err != nil {
return err
}
opts, done, err := cmd.sender.transactOpts(ctx, client)
opts, done, err := cmd.sender.transactOpts(ctx, cmd.client.nicknames, client)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions dep_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import (
"github.com/zeebo/clingy"

"storj.io/briskitall/internal/eth"
"storj.io/briskitall/internal/multisig"
)

type depClient struct {
nodeURL string
gasEstimateMultiplier float64
nicknames multisig.Nicknames
}

func (dep *depClient) setup(params clingy.Parameters) {
dep.nodeURL = requiredStringEnvFlag(params, "node-url", "Ethereum Node URL", envNodeURL)
dep.gasEstimateMultiplier = float64Flag(params, "gas-estimate-multiplier", "Multiplier on the estimated gas price", 2.0)
dep.nicknames = optionalNicknameMap(params, "address-nicknames", "A comma separated list of wallet address nickname definitions, like name1:address,name2:address", nil, envAddressNicknames)
}

func (dep *depClient) open(ctx context.Context) (eth.Client, error) {
Expand Down
2 changes: 1 addition & 1 deletion dep_multisig_transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (dep *depMultiSigTransactor) open(ctx context.Context) (*multisig.Transacto
return nil, nil, err
}

opts, done, err := dep.sender.transactOpts(ctx, client)
opts, done, err := dep.sender.transactOpts(ctx, dep.client.nicknames, client)
if err != nil {
return nil, nil, err
}
Expand Down
17 changes: 11 additions & 6 deletions dep_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/zeebo/errs"

"storj.io/briskitall/internal/eth"
"storj.io/briskitall/internal/multisig"
)

var (
Expand All @@ -39,7 +40,7 @@ func (dep *depSender) setup(params clingy.Parameters) {
dep.gasLimit = uint64Flag(params, "gas-limit", "Sets the transaction gas limit (0 = estimate)", 0)
}

func (dep *depSender) transactOpts(ctx context.Context, client bind.ContractTransactor) (opts *bind.TransactOpts, done func(), err error) {
func (dep *depSender) transactOpts(ctx context.Context, nicknames multisig.Nicknames, client bind.ContractTransactor) (opts *bind.TransactOpts, done func(), err error) {
done = func() {}

senderChoices := 0
Expand Down Expand Up @@ -97,23 +98,27 @@ func (dep *depSender) transactOpts(ctx context.Context, client bind.ContractTran
}
}

opts.Signer = confirmingSigner(ctx, opts.Signer, dep.skipConfirmation, isUSBWallet)
opts.Signer = confirmingSigner(ctx, nicknames, opts.Signer, dep.skipConfirmation, isUSBWallet)
opts.GasLimit = dep.gasLimit
opts.Context = ctx
return opts, done, nil
}

func confirmingSigner(ctx context.Context, signer bind.SignerFn, skip, isUSBWallet bool) bind.SignerFn {
func confirmingSigner(ctx context.Context, nicknames multisig.Nicknames, signer bind.SignerFn, skip, isUSBWallet bool) bind.SignerFn {
return bind.SignerFn(func(sender common.Address, tx *types.Transaction) (*types.Transaction, error) {
in := clingy.Stdin(ctx)
out := clingy.Stdout(ctx)

call := tryDecodeCall(tx.Data())
call := tryDecodeCall(nicknames, tx.Data())

fmt.Fprintf(out, "Preparing to send transaction:\n")
fmt.Fprintf(out, " Type...........: %s\n", txType(tx.Type()))
fmt.Fprintf(out, " From...........: %s\n", sender)
fmt.Fprintf(out, " To.............: %s\n", tx.To())
fmt.Fprintf(out, " From...........: %s\n", nicknames.Lookup(sender))
to := ""
if txTo := tx.To(); txTo != nil {
to = nicknames.Lookup(*txTo)
}
fmt.Fprintf(out, " To.............: %s\n", to)
switch {
case len(tx.Data()) == 0:
fmt.Fprintf(out, " Value..........: %s\n", eth.Pretty(tx.Value()))
Expand Down
1 change: 1 addition & 0 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ const (
envSenderKeyFile = "BRISKITALL_SENDER_KEY_FILE"
envUSBWalletAccount = "BRISKITALL_USB_WALLET_ACCOUNT"
envSkipConfirmation = "BRISKITALL_SKIP_CONFIRMATION"
envAddressNicknames = "BRISKITALL_ADDRESS_NICKNAMES"
)
61 changes: 56 additions & 5 deletions internal/multisig/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,52 @@ import (
"sort"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/zeebo/errs"

"storj.io/briskitall/internal/contract"
)

type NicknameMap map[common.Address]string

func (m NicknameMap) Lookup(wallet common.Address) string {
if entry, exists := m[wallet]; exists {
return entry
}
return wallet.String()
}

type Nicknames interface {
Lookup(wallet common.Address) (name string)
}

type Event interface {
String() string
StringWithNicknames(Nicknames) string

blockNumber() uint64
}

type confirmationEvent contract.MultiSigWalletConfirmation

func (e *confirmationEvent) String() string {
return fmt.Sprintf("ETH[%s]: Confirmation(%s)", e.Raw.TxHash, e.Sender)
return e.StringWithNicknames(NicknameMap(nil))
}

func (e *confirmationEvent) StringWithNicknames(n Nicknames) string {
return fmt.Sprintf("ETH[%s]: Confirmation(%s)", e.Raw.TxHash, n.Lookup(e.Sender))
}

func (e *confirmationEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

type revocationEvent contract.MultiSigWalletRevocation

func (e *revocationEvent) String() string {
return fmt.Sprintf("ETH[%s]: Revocation(%s)", e.Raw.TxHash, e.Sender)
return e.StringWithNicknames(NicknameMap(nil))
}

func (e *revocationEvent) StringWithNicknames(n Nicknames) string {
return fmt.Sprintf("ETH[%s]: Revocation(%s)", e.Raw.TxHash, n.Lookup(e.Sender))
}

func (e *revocationEvent) blockNumber() uint64 { return e.Raw.BlockNumber }
Expand All @@ -39,6 +62,10 @@ func (e *submissionEvent) String() string {
return fmt.Sprintf("ETH[%s]: Submission()", e.Raw.TxHash)
}

func (e *submissionEvent) StringWithNicknames(n Nicknames) string {
return e.String()
}

func (e *submissionEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

type executionEvent contract.MultiSigWalletExecution
Expand All @@ -47,6 +74,10 @@ func (e *executionEvent) String() string {
return fmt.Sprintf("ETH[%s]: Execution()", e.Raw.TxHash)
}

func (e *executionEvent) StringWithNicknames(n Nicknames) string {
return e.String()
}

func (e *executionEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

type executionFailureEvent contract.MultiSigWalletExecutionFailure
Expand All @@ -55,28 +86,44 @@ func (e *executionFailureEvent) String() string {
return fmt.Sprintf("ETH[%s]: ExecutionFailure()", e.Raw.TxHash)
}

func (e *executionFailureEvent) StringWithNicknames(n Nicknames) string {
return e.String()
}

func (e *executionFailureEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

type depositEvent contract.MultiSigWalletDeposit

func (e *depositEvent) String() string {
return fmt.Sprintf("ETH[%s]: Deposit(%s, %s)", e.Raw.TxHash, e.Sender, e.Value)
return e.StringWithNicknames(NicknameMap(nil))
}

func (e *depositEvent) StringWithNicknames(n Nicknames) string {
return fmt.Sprintf("ETH[%s]: Deposit(%s, %s)", e.Raw.TxHash, n.Lookup(e.Sender), e.Value)
}

func (e *depositEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

type ownerAdditionEvent contract.MultiSigWalletOwnerAddition

func (e *ownerAdditionEvent) String() string {
return fmt.Sprintf("ETH[%s]: OwnerAddition(%s)", e.Raw.TxHash, e.Owner)
return e.StringWithNicknames(NicknameMap(nil))
}

func (e *ownerAdditionEvent) StringWithNicknames(n Nicknames) string {
return fmt.Sprintf("ETH[%s]: OwnerAddition(%s)", e.Raw.TxHash, n.Lookup(e.Owner))
}

func (e *ownerAdditionEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

type ownerRemovalEvent contract.MultiSigWalletOwnerRemoval

func (e *ownerRemovalEvent) String() string {
return fmt.Sprintf("ETH[%s]: OwnerRemoval(%s)", e.Raw.TxHash, e.Owner)
return e.StringWithNicknames(NicknameMap(nil))
}

func (e *ownerRemovalEvent) StringWithNicknames(n Nicknames) string {
return fmt.Sprintf("ETH[%s]: OwnerRemoval(%s)", e.Raw.TxHash, n.Lookup(e.Owner))
}

func (e *ownerRemovalEvent) blockNumber() uint64 { return e.Raw.BlockNumber }
Expand All @@ -87,6 +134,10 @@ func (e *requirementChangeEvent) String() string {
return fmt.Sprintf("ETH[%s]: RequirementChanged(%s)", e.Raw.TxHash, e.Required)
}

func (e *requirementChangeEvent) StringWithNicknames(n Nicknames) string {
return e.String()
}

func (e *requirementChangeEvent) blockNumber() uint64 { return e.Raw.BlockNumber }

func getAllEvents(opts *bind.FilterOpts, filterer *contract.MultiSigWalletWithDailyLimitFilterer) ([]Event, error) {
Expand Down
Loading

0 comments on commit 1d41e7e

Please sign in to comment.