[wip] nitro server
This commit is contained in:
parent
01204261b7
commit
64d1a6d283
@ -20,6 +20,7 @@ import (
|
||||
slashingkeeper "cosmossdk.io/x/slashing/keeper"
|
||||
stakingkeeper "cosmossdk.io/x/staking/keeper"
|
||||
"git.vdb.to/cerc-io/laconicd/server/distsig"
|
||||
"git.vdb.to/cerc-io/laconicd/server/nitro"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
auctionkeeper "git.vdb.to/cerc-io/laconicd/x/auction/keeper"
|
||||
bondkeeper "git.vdb.to/cerc-io/laconicd/x/bond/keeper"
|
||||
@ -74,8 +75,7 @@ type LaconicApp[T Tx] struct {
|
||||
txConfig client.TxConfig
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
store store.RootStore
|
||||
|
||||
distsigManager *distsig.Manager
|
||||
distsigManager *distsig.Manager
|
||||
|
||||
// basic keepers
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
@ -147,6 +147,7 @@ func NewLaconicApp[T Tx](
|
||||
&app.txConfig,
|
||||
&app.interfaceRegistry,
|
||||
&app.distsigManager,
|
||||
// modules
|
||||
&app.StakingKeeper,
|
||||
&app.AccountKeeper,
|
||||
&app.BankKeeper,
|
||||
|
@ -50,6 +50,7 @@ type CommandDependencies[T app.Tx] struct {
|
||||
ConsensusServer *cometbft.CometBFTServer[T]
|
||||
ClientContext client.Context
|
||||
DistSigManager *distsig.Manager
|
||||
NitroServer *nitro.Server
|
||||
}
|
||||
|
||||
func InitRootCmd[T app.Tx](
|
||||
@ -158,10 +159,6 @@ func InitRootCmd[T app.Tx](
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nitroServer, err := nitro.NewServer(logger, deps.GlobalConfig, deps.ClientContext.Keyring)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// wire server commands
|
||||
return serverv2.AddCommands[T](
|
||||
@ -176,7 +173,7 @@ func InitRootCmd[T app.Tx](
|
||||
telemetryServer,
|
||||
restServer,
|
||||
gqlServer,
|
||||
nitroServer,
|
||||
deps.NitroServer,
|
||||
deps.DistSigManager,
|
||||
)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/app"
|
||||
"git.vdb.to/cerc-io/laconicd/server/distsig"
|
||||
"git.vdb.to/cerc-io/laconicd/server/nitro"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -76,6 +77,7 @@ func NewRootCmd[T app.Tx](
|
||||
clientCtx client.Context
|
||||
laconic *app.LaconicApp[T]
|
||||
dsManager *distsig.Manager
|
||||
nitroServer *nitro.Server
|
||||
depinjectConfig = depinject.Configs(
|
||||
depinject.Supply(logger, runtime.GlobalConfig(configMap)),
|
||||
depinject.Provide(
|
||||
@ -88,7 +90,7 @@ func NewRootCmd[T app.Tx](
|
||||
// server construction
|
||||
laconic, err = app.NewLaconicApp[T](
|
||||
depinjectConfig,
|
||||
&autoCliOpts, &moduleManager, &clientCtx, &dsManager,
|
||||
&autoCliOpts, &moduleManager, &clientCtx, &dsManager, &nitroServer,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -100,7 +102,7 @@ func NewRootCmd[T app.Tx](
|
||||
app.AppConfig(),
|
||||
depinjectConfig,
|
||||
),
|
||||
&autoCliOpts, &moduleManager, &clientCtx, &dsManager,
|
||||
&autoCliOpts, &moduleManager, &clientCtx, &dsManager, &nitroServer,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -112,6 +114,7 @@ func NewRootCmd[T app.Tx](
|
||||
LaconicApp: laconic,
|
||||
ClientContext: clientCtx,
|
||||
DistSigManager: dsManager,
|
||||
NitroServer: nitroServer,
|
||||
}
|
||||
rootCommand = &cobra.Command{
|
||||
Use: "laconicd",
|
||||
|
70
server/nitro/commands.go
Normal file
70
server/nitro/commands.go
Normal file
@ -0,0 +1,70 @@
|
||||
package nitro
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/statechannels/go-nitro/channel/state/outcome"
|
||||
gonitrotypes "github.com/statechannels/go-nitro/types"
|
||||
)
|
||||
|
||||
const (
|
||||
FlagAssetAddress = "asset"
|
||||
)
|
||||
|
||||
func (s *Server) OpenChannel() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "open-channel <amount>", // TODO: doc args?
|
||||
Short: "Open a payment channel with the Laconic custodian",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// clientCtx, err := client.GetClientTxContext(cmd)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// TODO
|
||||
// use Coin types for eth and tokens?
|
||||
// how do we map denoms to addresses?
|
||||
amount, ok := new(big.Int).SetString(args[1], 10)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid amount: %s", args[1])
|
||||
}
|
||||
assetStr, err := cmd.Flags().GetString(FlagAssetAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var asset common.Address // 0 address mean ETH
|
||||
if assetStr != "" {
|
||||
asset = common.HexToAddress(assetStr)
|
||||
}
|
||||
|
||||
destination := LaconicCustodianAddress
|
||||
exit := outcome.Exit{
|
||||
outcome.SingleAssetExit{
|
||||
Asset: asset,
|
||||
Allocations: []outcome.Allocation{
|
||||
{ // TODO: what should initial allocation be?
|
||||
Destination: gonitrotypes.AddressToDestination(s.EthAddress),
|
||||
Amount: amount,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
r, err := s.CreateLedgerChannel(destination, 0, exit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.Println("objective response:", r)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmd.Flags().String(FlagAssetAddress, "", "The address of the asset to fund the channel with")
|
||||
addClientFlags(cmd.Flags())
|
||||
|
||||
return cmd
|
||||
}
|
@ -4,7 +4,7 @@ type Config struct {
|
||||
// TODO: use keyring
|
||||
Pk string `mapstructure:"pk" toml:"pk" comment:"The private key used by the Nitro node."`
|
||||
|
||||
// EthPk string `mapstructure:"eth-pk" toml:"eth-pk" comment:"eth-pk specifies the private key to use when interacting with the Ethereum chain."`
|
||||
EthPk string `mapstructure:"eth-pk" toml:"eth-pk" comment:"The private key used when interacting with the Ethereum chain."`
|
||||
EthUrl string `mapstructure:"eth-url" toml:"eth-url" comment:"The URL of the Ethereum node to connect to."`
|
||||
EthAuthToken string `mapstructure:"eth-auth-token" toml:"eth-auth-token" comment:"The bearer token used for auth in requests to the Ethereum chain's RPC endpoint."`
|
||||
EthStartBlock uint64 `mapstructure:"eth-start-block" toml:"eth-start-block" comment:"Ethereum block number to start listening for Nitro Adjudicator events."`
|
||||
|
23
server/nitro/dev_account.go
Normal file
23
server/nitro/dev_account.go
Normal file
@ -0,0 +1,23 @@
|
||||
package nitro
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
)
|
||||
|
||||
var (
|
||||
// (DEV) EOA placeholder for consensus-controlled smart contract account
|
||||
LaconicCustodianAddress common.Address
|
||||
LaconicCustodianPrivKey = secp256k1.PrivKey{Key: crypto.Keccak256([]byte("laconic-custodian"))}
|
||||
// LaconicCustodianPrivKey *ecdsa.PrivateKey
|
||||
)
|
||||
|
||||
func init() {
|
||||
ecdsaPrivKey, err := crypto.ToECDSA(LaconicCustodianPrivKey.Key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
LaconicCustodianAddress = crypto.PubkeyToAddress(ecdsaPrivKey.PublicKey)
|
||||
}
|
@ -14,7 +14,7 @@ func prefix(f string) string {
|
||||
var (
|
||||
flag_pk = prefix("pk") // "pk"
|
||||
|
||||
// flag_eth_pk = prefix("eth-pk") // "chainpk"
|
||||
flag_eth_pk = prefix("eth-pk") // "chainpk"
|
||||
flag_eth_url = prefix("eth-url") // "chainurl"
|
||||
flag_eth_start_block = prefix("eth-start-block") // "chainstartblock"
|
||||
flag_eth_auth_token = prefix("eth-auth-token") // "chainauthtoken"
|
||||
@ -34,7 +34,7 @@ var (
|
||||
// flag_gui_port = prefix("gui-port") // "guiport"
|
||||
)
|
||||
|
||||
func AddNitroFlags(flags *pflag.FlagSet) {
|
||||
func addServerFlags(flags *pflag.FlagSet) {
|
||||
flags.String(flag_pk, "",
|
||||
"name of private key used by the Nitro node",
|
||||
// EnvVars: []string{"SC_PK"},
|
||||
@ -47,10 +47,6 @@ func AddNitroFlags(flags *pflag.FlagSet) {
|
||||
"bearer token used for auth in requests to the Ethereum chain's RPC endpoint",
|
||||
// EnvVars: []string{"CHAIN_AUTH_TOKEN"},
|
||||
)
|
||||
// flags.String(flag_eth_pk, "",
|
||||
// "name of private key to use when interacting with the Ethereum chain",
|
||||
// // EnvVars: []string{"CHAIN_PK"},
|
||||
// )
|
||||
flags.Uint64(flag_eth_start_block, 0,
|
||||
"Ethereum block number to start listening for Nitro Adjudicator events",
|
||||
// EnvVars: []string{"CHAIN_START_BLOCK"},
|
||||
@ -96,3 +92,12 @@ func AddNitroFlags(flags *pflag.FlagSet) {
|
||||
"filepath to the TLS private key; if not specified, TLS will not be used with the RPC transport",
|
||||
)
|
||||
}
|
||||
|
||||
func addClientFlags(flags *pflag.FlagSet) {
|
||||
// TODO: this is only used by "client" (user) nodes
|
||||
flags.String(flag_eth_pk, "",
|
||||
"name of private key to use when interacting with the Ethereum chain",
|
||||
// EnvVars: []string{"CHAIN_PK"},
|
||||
)
|
||||
addServerFlags(flags)
|
||||
}
|
||||
|
@ -3,16 +3,15 @@ package nitro
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/statechannels/go-nitro/crypto"
|
||||
"github.com/statechannels/go-nitro/node"
|
||||
"github.com/statechannels/go-nitro/node/engine"
|
||||
"github.com/statechannels/go-nitro/node/engine/chainservice"
|
||||
@ -20,11 +19,12 @@ import (
|
||||
"github.com/statechannels/go-nitro/node/engine/store"
|
||||
nitrotypes "github.com/statechannels/go-nitro/types"
|
||||
|
||||
"cosmossdk.io/core/server"
|
||||
"cosmossdk.io/core/transaction"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/runtime/v2"
|
||||
serverv2 "cosmossdk.io/server/v2"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
)
|
||||
@ -53,45 +53,46 @@ type Server struct {
|
||||
logger log.Logger
|
||||
config *Config
|
||||
|
||||
// name of Ethereum private key used for chain txs
|
||||
EthKey string
|
||||
// path to Nitro store directory
|
||||
storeDir string
|
||||
|
||||
// EthAddress common.Address
|
||||
EthAddress common.Address
|
||||
StateChannelAddress nitrotypes.PartyAddress
|
||||
}
|
||||
|
||||
func NewServer(logger log.Logger, cfg server.ConfigMap, kr keyring.Keyring) (*Server, error) {
|
||||
home, _ := cfg[serverv2.FlagHome].(string)
|
||||
func NewServer(logger log.Logger, cfg *Config, kr keyring.Keyring, storeDir string) (*Server, error) {
|
||||
s := &Server{
|
||||
storeDir: filepath.Join(home, "nitro"),
|
||||
storeDir: storeDir,
|
||||
config: cfg,
|
||||
}
|
||||
s.logger = logger.With(log.ModuleKey, s.Name())
|
||||
|
||||
s.config = s.Config().(*Config)
|
||||
if len(cfg) > 0 {
|
||||
if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), s.config); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
||||
}
|
||||
}
|
||||
return s, s.init(kr)
|
||||
}
|
||||
|
||||
func (s *Server) init(kr keyring.Keyring) error {
|
||||
var err error
|
||||
c := s.config
|
||||
|
||||
var ethkey cryptotypes.PrivKey
|
||||
if c.EthPk != "" {
|
||||
ethkey, err = utils.ExtractPrivateKey(kr, c.EthPk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// TODO for server, inject signer or callback into nitro node instead of naked privkey
|
||||
// client case is simple signature
|
||||
// for validator, multisignatures can be negotiated over abci txs, then loaded into signer
|
||||
// Sign(message) only passes once validator's signature is prepared
|
||||
s.logger.Warn("(DEV) using fake Laconic custodian Ethereum private key")
|
||||
ethkey = &LaconicCustodianPrivKey
|
||||
}
|
||||
|
||||
sckey, err := utils.ExtractPrivateKey(kr, c.Pk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO inject signer or callback into nitro node instead of naked privkey
|
||||
// signer.Sign(message)
|
||||
// client case is simple signature
|
||||
// for validator, multisignatures can be negotiated over abci txs, then loaded into signer
|
||||
// Sign(message) only passes once validator's signature is prepared
|
||||
|
||||
storeOpts := store.StoreOpts{
|
||||
PkBytes: sckey.Bytes(),
|
||||
UseDurableStore: true,
|
||||
@ -114,7 +115,7 @@ func (s *Server) init(kr keyring.Keyring) error {
|
||||
ChainStartBlockNum: c.EthStartBlock,
|
||||
ChainAuthToken: c.EthAuthToken,
|
||||
// TODO delegation to distsig
|
||||
// ChainPk: hex.EncodeToString(ethkey),
|
||||
ChainPk: hex.EncodeToString(ethkey.Bytes()),
|
||||
NaAddress: common.HexToAddress(c.EthNaAddress),
|
||||
VpaAddress: common.HexToAddress(c.EthVpaAddress),
|
||||
CaAddress: common.HexToAddress(c.EthCaAddress),
|
||||
@ -122,7 +123,7 @@ func (s *Server) init(kr keyring.Keyring) error {
|
||||
// Inject SDK logger into slog, which Nitro uses
|
||||
loggerImpl, ok := s.logger.Impl().(*slog.Logger)
|
||||
if !ok {
|
||||
return errors.New("logger does not have slog implementation")
|
||||
s.logger.Warn("logger does not have slog implementation")
|
||||
}
|
||||
slog.SetDefault(loggerImpl)
|
||||
|
||||
@ -130,8 +131,13 @@ func (s *Server) init(kr keyring.Keyring) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// note: utils.EthAddressFromPubKey only works with uncompressed keys
|
||||
ethPubkey, err := crypto.DecompressPubkey(ethkey.PubKey().Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.Node = node
|
||||
// s.EthAddress = crypto.GetAddressFromSecretKeyBytes(ethkey)
|
||||
s.EthAddress = crypto.PubkeyToAddress(*ethPubkey)
|
||||
s.StateChannelAddress = *store.GetAddress()
|
||||
return nil
|
||||
}
|
||||
@ -210,7 +216,7 @@ func (s *Server) Config() any {
|
||||
|
||||
func (s *Server) StartCmdFlags() *pflag.FlagSet {
|
||||
flags := pflag.NewFlagSet(s.Name(), pflag.ExitOnError)
|
||||
AddNitroFlags(flags)
|
||||
addServerFlags(flags)
|
||||
return flags
|
||||
}
|
||||
|
||||
@ -225,3 +231,20 @@ func (s *Server) CLICommands() serverv2.CLIConfig {
|
||||
// Queries: []*cobra.Command{},
|
||||
}
|
||||
}
|
||||
|
||||
func UnmarshalConfig(cfg map[string]any) (*Config, error) {
|
||||
config := DefaultConfig()
|
||||
if err := serverv2.UnmarshalSubConfig(cfg, serverName, config); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal %T: %w", config, err)
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func ProvideServer(logger log.Logger, globalConfig runtime.GlobalConfig, kr keyring.Keyring) (*Server, error) {
|
||||
home, _ := globalConfig[serverv2.FlagHome].(string)
|
||||
config, err := UnmarshalConfig(globalConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewServer(logger, config, kr, filepath.Join(home, "nitro"))
|
||||
}
|
||||
|
@ -2,16 +2,51 @@ package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/address"
|
||||
appmodule "cosmossdk.io/core/appmodule/v2"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/server/distsig"
|
||||
"git.vdb.to/cerc-io/laconicd/x/nitrobank"
|
||||
)
|
||||
|
||||
type Keeper struct {
|
||||
appmodule.Environment
|
||||
addressCodec address.Codec
|
||||
// logger log.Logger
|
||||
|
||||
// use interface from bank module
|
||||
acctKeeper banktypes.AccountKeeper
|
||||
accountKeeper banktypes.AccountKeeper
|
||||
distsigManager *distsig.Manager
|
||||
|
||||
ChannelProposals collections.Map[string, nitrobank.MsgProposeChannel]
|
||||
}
|
||||
|
||||
func NewKeeper(
|
||||
cdc codec.BinaryCodec,
|
||||
env appmodule.Environment,
|
||||
addressCodec address.Codec,
|
||||
accountKeeper banktypes.AccountKeeper,
|
||||
distsigManager *distsig.Manager,
|
||||
) Keeper {
|
||||
sb := collections.NewSchemaBuilder(env.KVStoreService)
|
||||
return Keeper{
|
||||
Environment: env,
|
||||
addressCodec: addressCodec,
|
||||
accountKeeper: accountKeeper,
|
||||
distsigManager: distsigManager,
|
||||
ChannelProposals: collections.NewMap(
|
||||
sb, nitrobank.ChannelProposalsPrefix, "channel_proposals",
|
||||
collections.StringKey, codec.CollValue[nitrobank.MsgProposeChannel](cdc),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// func (k Keeper) EnsurePaymentChannel(from, to sdk.AccAddress, amount sdk.Coins) error {
|
||||
@ -20,4 +55,36 @@ func (k Keeper) EnsurePaymentChannel(from sdk.AccAddress, to string, amount sdk.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) ProposeChannel(ctx context.Context) {}
|
||||
func (k Keeper) ProposeChannel(ctx context.Context, req *nitrobank.MsgProposeChannel) error {
|
||||
from, err := k.addressCodec.StringToBytes(req.FromAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
account := k.accountKeeper.GetAccount(ctx, from)
|
||||
proposalId := proposalID{
|
||||
from: from,
|
||||
accnum: account.GetAccountNumber(),
|
||||
seqnum: account.GetSequence(),
|
||||
}.generate(k.addressCodec)
|
||||
// if err := k.distsigManager.StartSignature(); err != nil {
|
||||
// return err
|
||||
// }
|
||||
return k.ChannelProposals.Set(ctx, proposalId, *req)
|
||||
}
|
||||
|
||||
type proposalID struct {
|
||||
from sdk.AccAddress
|
||||
accnum uint64
|
||||
seqnum uint64
|
||||
}
|
||||
|
||||
func (id proposalID) generate(ac address.Codec) string {
|
||||
hasher := sha256.New()
|
||||
addrStr, err := ac.BytesToString(id.from.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
str := fmt.Sprintf("%s:%d:%d", addrStr, id.accnum, id.seqnum)
|
||||
hasher.Write([]byte(str))
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
|
33
x/nitrobank/keeper/msg_server.go
Normal file
33
x/nitrobank/keeper/msg_server.go
Normal file
@ -0,0 +1,33 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/event"
|
||||
"git.vdb.to/cerc-io/laconicd/x/nitrobank"
|
||||
)
|
||||
|
||||
func NewMsgServer(k Keeper) *msgServer {
|
||||
return &msgServer{k}
|
||||
}
|
||||
|
||||
type msgServer struct {
|
||||
k Keeper
|
||||
}
|
||||
|
||||
func (m msgServer) ProposeChannel(ctx context.Context, req *nitrobank.MsgProposeChannel) (*nitrobank.MsgProposeChannelResponse, error) {
|
||||
if err := m.k.ProposeChannel(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eventManager := m.k.EventService.EventManager(ctx)
|
||||
if err := eventManager.EmitKV(
|
||||
"channel_proposal",
|
||||
event.NewAttribute("from", req.FromAddress),
|
||||
// event.NewAttribute("to", req.ToAddress),
|
||||
event.NewAttribute("funds", req.Funds.String()),
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &nitrobank.MsgProposeChannelResponse{}, nil
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package nitrobank
|
||||
|
||||
// import "cosmossdk.io/collections"
|
||||
import "cosmossdk.io/collections"
|
||||
|
||||
const (
|
||||
ModuleName = "nitrobank"
|
||||
@ -11,5 +11,7 @@ const (
|
||||
|
||||
// Store prefixes
|
||||
var (
|
||||
// ParamsPrefix = collections.NewPrefix(0)
|
||||
ParamsPrefix = collections.NewPrefix(0)
|
||||
|
||||
ChannelProposalsPrefix = collections.NewPrefix(1)
|
||||
)
|
||||
|
@ -6,6 +6,8 @@ package nitrobank
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
|
||||
types "github.com/cosmos/cosmos-sdk/types"
|
||||
_ "github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
grpc1 "github.com/cosmos/gogoproto/grpc"
|
||||
@ -215,10 +217,9 @@ var xxx_messageInfo_MsgOpenChannelResponse proto.InternalMessageInfo
|
||||
type MsgProposeChannel struct {
|
||||
// Nitro address of sending party (payer)
|
||||
FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"`
|
||||
// Nitro address of counterparty
|
||||
ToAddress string `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty"`
|
||||
// Simplified outcome just includes the funding amount from payer
|
||||
Amount string `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"`
|
||||
// TODO: review use of coins to represent ETH/ERC20
|
||||
Funds github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=funds,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"funds"`
|
||||
}
|
||||
|
||||
func (m *MsgProposeChannel) Reset() { *m = MsgProposeChannel{} }
|
||||
@ -261,18 +262,11 @@ func (m *MsgProposeChannel) GetFromAddress() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *MsgProposeChannel) GetToAddress() string {
|
||||
func (m *MsgProposeChannel) GetFunds() github_com_cosmos_cosmos_sdk_types.Coins {
|
||||
if m != nil {
|
||||
return m.ToAddress
|
||||
return m.Funds
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *MsgProposeChannel) GetAmount() string {
|
||||
if m != nil {
|
||||
return m.Amount
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
type MsgProposeChannelResponse struct {
|
||||
@ -323,32 +317,38 @@ func init() {
|
||||
func init() { proto.RegisterFile("cerc/nitrobank/v1/tx.proto", fileDescriptor_7647fae54567b5bd) }
|
||||
|
||||
var fileDescriptor_7647fae54567b5bd = []byte{
|
||||
// 400 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x92, 0xc1, 0x6a, 0x1a, 0x41,
|
||||
0x18, 0xc7, 0x1d, 0xa5, 0x82, 0x53, 0x2b, 0xb8, 0x14, 0x6b, 0xb7, 0xed, 0x52, 0xb7, 0x42, 0x8b,
|
||||
0xb4, 0x3b, 0xd8, 0xd2, 0x4b, 0x6f, 0xb6, 0xa7, 0x1e, 0xa4, 0xc5, 0x63, 0x2f, 0x32, 0xce, 0x4e,
|
||||
0x27, 0x4b, 0xdc, 0xf9, 0x96, 0x9d, 0x89, 0x78, 0x09, 0x88, 0x4f, 0x20, 0xe4, 0x01, 0xf2, 0x0a,
|
||||
0x3e, 0x46, 0x8e, 0x42, 0x2e, 0x39, 0x06, 0x0d, 0xf8, 0x1a, 0x61, 0xc7, 0x55, 0xa3, 0x7b, 0xc9,
|
||||
0x2d, 0xb7, 0xd9, 0xef, 0xff, 0xff, 0x7e, 0xff, 0x3f, 0xcb, 0x87, 0x6d, 0xc6, 0x63, 0x46, 0x64,
|
||||
0xa0, 0x63, 0x18, 0x50, 0x79, 0x4a, 0x46, 0x6d, 0xa2, 0xc7, 0x5e, 0x14, 0x83, 0x06, 0xab, 0x9a,
|
||||
0x68, 0xde, 0x4e, 0xf3, 0x46, 0x6d, 0xfb, 0x15, 0x03, 0x15, 0x82, 0x22, 0xa1, 0x12, 0x89, 0x35,
|
||||
0x54, 0x62, 0xe3, 0xb5, 0x5f, 0x0a, 0x10, 0x60, 0x9e, 0x24, 0x79, 0xa5, 0xd3, 0xb7, 0x02, 0x40,
|
||||
0x0c, 0x39, 0xa1, 0x51, 0x40, 0xa8, 0x94, 0xa0, 0xa9, 0x0e, 0x40, 0xaa, 0x54, 0x6d, 0x64, 0xb3,
|
||||
0xf7, 0x61, 0xc6, 0xe2, 0x7e, 0xc7, 0x95, 0xae, 0x12, 0xbf, 0x65, 0xa0, 0x3b, 0x8c, 0xc1, 0x99,
|
||||
0xd4, 0xd6, 0x07, 0xfc, 0xc2, 0x98, 0xfa, 0xd4, 0xf7, 0x63, 0xae, 0x54, 0x1d, 0xbd, 0x47, 0x9f,
|
||||
0x4a, 0xbd, 0xb2, 0x19, 0x76, 0x36, 0x33, 0xb7, 0x8e, 0x6b, 0x87, 0x6b, 0x3d, 0xae, 0x22, 0x90,
|
||||
0x8a, 0xbb, 0xe7, 0x06, 0xf8, 0x27, 0xe2, 0xf2, 0xd7, 0x09, 0x95, 0x92, 0x0f, 0xad, 0x06, 0x2e,
|
||||
0xff, 0x8f, 0x21, 0x3c, 0xe2, 0x3d, 0x4f, 0x66, 0x29, 0xce, 0x7a, 0x87, 0xb1, 0xde, 0x07, 0xe6,
|
||||
0x8d, 0xa1, 0xa4, 0xb7, 0x69, 0x56, 0x0d, 0x17, 0x69, 0x98, 0xa4, 0xd4, 0x0b, 0x46, 0x4a, 0xbf,
|
||||
0x7e, 0x54, 0xa7, 0xeb, 0x79, 0xeb, 0x00, 0x9e, 0x16, 0x7b, 0x10, 0xbf, 0x2b, 0x36, 0x41, 0xb8,
|
||||
0xda, 0x55, 0xe2, 0x6f, 0x0c, 0x11, 0x28, 0xfe, 0x24, 0xe5, 0xde, 0xe0, 0xd7, 0x99, 0x06, 0xdb,
|
||||
0x7e, 0x5f, 0x2f, 0x11, 0x2e, 0x74, 0x95, 0xb0, 0x66, 0x08, 0x57, 0x8e, 0x4a, 0x36, 0xbd, 0xcc,
|
||||
0xa1, 0x78, 0x19, 0x90, 0xfd, 0xf9, 0x31, 0xae, 0xdd, 0xef, 0x68, 0x4d, 0xaf, 0xef, 0x2e, 0xf2,
|
||||
0x4d, 0xd7, 0x25, 0xd9, 0x23, 0x89, 0x36, 0x2b, 0x7d, 0x96, 0x92, 0x9f, 0x4d, 0xd6, 0xf3, 0x16,
|
||||
0xfa, 0xd9, 0xb9, 0x5a, 0x3a, 0x68, 0xb1, 0x74, 0xd0, 0xed, 0xd2, 0x41, 0xb3, 0x95, 0x93, 0x5b,
|
||||
0xac, 0x9c, 0xdc, 0xcd, 0xca, 0xc9, 0xfd, 0xfb, 0x28, 0x02, 0xed, 0x8d, 0xfc, 0x81, 0xa7, 0xc1,
|
||||
0xe0, 0xbe, 0x04, 0x40, 0x86, 0x94, 0x81, 0x0c, 0x98, 0x4f, 0xc6, 0x7b, 0xf8, 0xa0, 0x68, 0xae,
|
||||
0xee, 0xdb, 0x7d, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf6, 0x95, 0xda, 0x82, 0x16, 0x03, 0x00, 0x00,
|
||||
// 481 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4f, 0x4f, 0x13, 0x41,
|
||||
0x14, 0xef, 0xd0, 0x40, 0xc2, 0x80, 0x24, 0xdd, 0x18, 0x2c, 0x55,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0xdf, 0xc8, 0xe0, 0x0c, 0xe1, 0xb5, 0x5b, 0x0d, 0x6d, 0x93, 0xca,
|
||||
0xd1, 0x91, 0x0a, 0x51, 0xeb, 0xe9, 0xbf, 0x64, 0xcd, 0x46, 0xd7, 0x39, 0xfd, 0xfa, 0xeb, 0xe3,
|
||||
0xc2, 0x76, 0x14, 0xd1, 0xea, 0x41, 0x65, 0x65, 0xc9, 0x01, 0xf7, 0xcc, 0x8b, 0x1f, 0xae, 0xce,
|
||||
0x3b, 0x68, 0xaf, 0x77, 0x31, 0x09, 0xd1, 0xe5, 0x24, 0x44, 0x3f, 0x27, 0x21, 0x3a, 0x9b, 0x86,
|
||||
0xb5, 0xcb, 0x69, 0x58, 0xfb, 0x36, 0x0d, 0x6b, 0x6f, 0x9f, 0x48, 0x65, 0xc9, 0x38, 0x89, 0x89,
|
||||
0x05, 0x47, 0xb7, 0xa3, 0x80, 0x0e, 0x19, 0x07, 0xad, 0x78, 0x42, 0x4f, 0xe6, 0xe4, 0xf1, 0x92,
|
||||
0xbb, 0xd0, 0xe7, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x95, 0xea, 0x36, 0x46, 0x62, 0x03, 0x00,
|
||||
0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@ -572,19 +572,19 @@ func (m *MsgProposeChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Amount) > 0 {
|
||||
i -= len(m.Amount)
|
||||
copy(dAtA[i:], m.Amount)
|
||||
i = encodeVarintTx(dAtA, i, uint64(len(m.Amount)))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
if len(m.ToAddress) > 0 {
|
||||
i -= len(m.ToAddress)
|
||||
copy(dAtA[i:], m.ToAddress)
|
||||
i = encodeVarintTx(dAtA, i, uint64(len(m.ToAddress)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
if len(m.Funds) > 0 {
|
||||
for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintTx(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if len(m.FromAddress) > 0 {
|
||||
i -= len(m.FromAddress)
|
||||
@ -692,13 +692,11 @@ func (m *MsgProposeChannel) Size() (n int) {
|
||||
if l > 0 {
|
||||
n += 1 + l + sovTx(uint64(l))
|
||||
}
|
||||
l = len(m.ToAddress)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovTx(uint64(l))
|
||||
}
|
||||
l = len(m.Amount)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovTx(uint64(l))
|
||||
if len(m.Funds) > 0 {
|
||||
for _, e := range m.Funds {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovTx(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
@ -1109,9 +1107,9 @@ func (m *MsgProposeChannel) Unmarshal(dAtA []byte) error {
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ToAddress", wireType)
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowTx
|
||||
@ -1121,55 +1119,25 @@ func (m *MsgProposeChannel) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.ToAddress = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType)
|
||||
m.Funds = append(m.Funds, types.Coin{})
|
||||
if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowTx
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Amount = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
|
Loading…
Reference in New Issue
Block a user