Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utxo): Add support for utxo chains #1220

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ func (tn *ChainNode) CreateNodeContainer(ctx context.Context) error {
fmt.Printf("Port Overrides: %v. Using: %v\n", chainCfg.HostPortOverride, usingPorts)
}

return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, usingPorts, tn.Bind(), nil, tn.HostName(), cmd, chainCfg.Env)
return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, usingPorts, tn.Bind(), nil, tn.HostName(), cmd, chainCfg.Env, []string{})
}

func (tn *ChainNode) StartContainer(ctx context.Context) error {
Expand Down
5 changes: 5 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ func (c *CosmosChain) SendFunds(ctx context.Context, keyName string, amount ibc.
return c.getFullNode().BankSend(ctx, keyName, amount)
}

// Implements Chain interface
func (c *CosmosChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
return c.getFullNode().BankSendWithNote(ctx, keyName, amount, note)
}
Reecepbcups marked this conversation as resolved.
Show resolved Hide resolved

// Implements Chain interface
func (c *CosmosChain) SendIBCTransfer(
ctx context.Context,
Expand Down
6 changes: 6 additions & 0 deletions chain/cosmos/module_bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func (tn *ChainNode) BankSend(ctx context.Context, keyName string, amount ibc.Wa
return err
}

// BankSend sends tokens from one account to another.
func (tn *ChainNode) BankSendWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
return tn.ExecTx(ctx, keyName, "bank", "send", keyName, amount.Address,
fmt.Sprintf("%s%s", amount.Amount.String(), amount.Denom), "--note", note)
}

// Deprecated: use BankSend instead
func (tn *ChainNode) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
return tn.BankSend(ctx, keyName, amount)
Expand Down
2 changes: 1 addition & 1 deletion chain/cosmos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *SidecarProcess) logger() *zap.Logger {
}

func (s *SidecarProcess) CreateContainer(ctx context.Context) error {
return s.containerLifecycle.CreateContainer(ctx, s.TestName, s.NetworkID, s.Image, s.ports, s.Bind(), nil, s.HostName(), s.startCmd, s.env)
return s.containerLifecycle.CreateContainer(ctx, s.TestName, s.NetworkID, s.Image, s.ports, s.Bind(), nil, s.HostName(), s.startCmd, s.env, []string{})
}

func (s *SidecarProcess) StartContainer(ctx context.Context) error {
Expand Down
35 changes: 34 additions & 1 deletion chain/ethereum/ethererum_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"strings"

"github.com/ethereum/go-ethereum/common/hexutil"
sdkmath "cosmossdk.io/math"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/mount"
Expand Down Expand Up @@ -222,7 +223,7 @@ func (c *EthereumChain) Start(testName string, ctx context.Context, additionalGe
fmt.Printf("Port Overrides: %v. Using: %v\n", c.cfg.HostPortOverride, usingPorts)
}

err := c.containerLifecycle.CreateContainer(ctx, c.testName, c.NetworkID, c.cfg.Images[0], usingPorts, c.Bind(), mounts, c.HostName(), cmd, nil)
err := c.containerLifecycle.CreateContainer(ctx, c.testName, c.NetworkID, c.cfg.Images[0], usingPorts, c.Bind(), mounts, c.HostName(), cmd, nil, []string{})
if err != nil {
return err
}
Expand Down Expand Up @@ -345,6 +346,38 @@ func (c *EthereumChain) SendFunds(ctx context.Context, keyName string, amount ib
return err
}

type TransactionReceipt struct {
TxHash string `json:"transactionHash"`
}

func (c *EthereumChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
cmd := []string{"cast", "send", amount.Address, hexutil.Encode([]byte(note)), "--value", amount.Amount.String(), "--json"}
if keyName == "faucet" {
cmd = append(cmd,
"--private-key", "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url", c.GetRPCAddress(),
)

} else {
cmd = append(cmd,
"--keystore", c.keystoreMap[keyName],
misko9 marked this conversation as resolved.
Show resolved Hide resolved
"--password", "",
"--rpc-url", c.GetRPCAddress(),
)
}
stdout, _, err := c.Exec(ctx, cmd, nil)
if err != nil {
return "", err
}

var txReceipt TransactionReceipt
if err = json.Unmarshal(stdout, &txReceipt); err != nil {
return "", err
}

return txReceipt.TxHash, nil
}

func (c *EthereumChain) Height(ctx context.Context) (int64, error) {
cmd := []string{"cast", "block-number", "--rpc-url", c.GetRPCAddress()}
stdout, _, err := c.Exec(ctx, cmd, nil)
Expand Down
2 changes: 1 addition & 1 deletion chain/internal/tendermint/tendermint_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (tn *TendermintNode) CreateNodeContainer(ctx context.Context, additionalFla
cmd := []string{chainCfg.Bin, "start", "--home", tn.HomeDir()}
cmd = append(cmd, additionalFlags...)

return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, sentryPorts, tn.Bind(), nil, tn.HostName(), cmd, nil)
return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, sentryPorts, tn.Bind(), nil, tn.HostName(), cmd, nil, []string{})
}

func (tn *TendermintNode) StopContainer(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion chain/penumbra/penumbra_app_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (p *PenumbraAppNode) CreateNodeContainer(ctx context.Context, tendermintAdd
"--home", p.HomeDir(),
}

return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env)
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env, []string{})
}

// StopContainer stops the running container for the PenumbraAppNode.
Expand Down
7 changes: 7 additions & 0 deletions chain/penumbra/penumbra_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ func (c *PenumbraChain) SendFunds(ctx context.Context, keyName string, amount ib
return fn.PenumbraClientNodes[keyName].SendFunds(ctx, amount)
}


// SendFundsWithNote will initiate a local transfer from the account associated with the specified keyName,
// amount, token denom, and recipient are specified in the amount and attach a note/memo
func (c *PenumbraChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
panic("Penumbrachain: SendFundsWithNote unimplemented")
}

// SendIBCTransfer attempts to send a fungible token transfer via IBC from the specified account on the source chain
// to the specified account on the counterparty chain.
func (c *PenumbraChain) SendIBCTransfer(
Expand Down
2 changes: 1 addition & 1 deletion chain/penumbra/penumbra_client_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func (p *PenumbraClientNode) CreateNodeContainer(ctx context.Context) error {
"start",
}

return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, pclientdPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env)
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, pclientdPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env, []string{})
}

// StopContainer stops the container associated with the PenumbraClientNode.
Expand Down
2 changes: 1 addition & 1 deletion chain/polkadot/parachain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (pn *ParachainNode) CreateNodeContainer(ctx context.Context) error {
cmd = append(cmd, "--", fmt.Sprintf("--chain=%s", pn.RawRelayChainSpecFilePathFull()))
cmd = append(cmd, pn.RelayChainFlags...)

return pn.containerLifecycle.CreateContainer(ctx, pn.TestName, pn.NetworkID, pn.Image, exposedPorts, pn.Bind(), nil, pn.HostName(), cmd, nil)
return pn.containerLifecycle.CreateContainer(ctx, pn.TestName, pn.NetworkID, pn.Image, exposedPorts, pn.Bind(), nil, pn.HostName(), cmd, nil, []string{})
}

// StopContainer stops the relay chain node container, waiting at most 30 seconds.
Expand Down
6 changes: 6 additions & 0 deletions chain/polkadot/polkadot_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,12 @@ func (c *PolkadotChain) SendFunds(ctx context.Context, keyName string, amount ib
return c.ParachainNodes[0][0].SendFunds(ctx, keyName, amount)
}

// SendFundsWithNote sends funds to a wallet from a user account with a note/memo.
// Implements Chain interface.
func (c *PolkadotChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
panic("PolkadotChain: SendFundsWithNote unimplemented")
}

// SendIBCTransfer sends an IBC transfer returning a transaction or an error if the transfer failed.
// Implements Chain interface.
func (c *PolkadotChain) SendIBCTransfer(
Expand Down
2 changes: 1 addition & 1 deletion chain/polkadot/relay_chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (p *RelayChainNode) CreateNodeContainer(ctx context.Context) error {
fmt.Sprintf("--public-addr=%s", multiAddress),
"--base-path", p.NodeHome(),
}
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, nil)
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, nil, []string{})
}

// StopContainer stops the relay chain node container, waiting at most 30 seconds.
Expand Down
Loading
Loading