-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial thorchain addition, configs setup, still need genesis update * wip: thorchain genesis * thorchain running * thorchain and bifrost working together * add savers, swaps, and saver eject example case for gaia * arb wip, all other sim tests passing * arb code in, needs testing with >1 pool * add ethereum to thorchain test and start cleaning up * clean up savers/arb features * clean up swap feature * cleanup of saver eject and ragnarok features * fix: second+ saver eject now works * Add back arbing and eth->gaia swap * wip, add utxo support, SendFundsWithNote() still needed * hardfork wip * start with genesis contents * progress further * wip: removed non-BTC chains temporarily, BTC's SendFundsWithNote succeeds. * thorchain<->btc dual lp working * btc and bch looking good * ltc working, clean up logging, fix coins funded on each chain, and fix utxo send amount * utxo chains fully operational * fix ether type * add some protections around utxo node wallet usage * send utxo change back to sender instead of a change address * Run tests in parallel * clean up utxo test * fmt/lint * More cleanup * increase time for bifrost to initialize * Set bifrost envs at runtime * change wg to eg * minor fmt * add back mainnet-genesis.json * remove mainnet-genesis.json * lint * fix: nil gRPC queries --------- Co-authored-by: Andrew Gouin <andrew@gouin.io> Co-authored-by: Reece Williams <reecepbcups@gmail.com>
- Loading branch information
1 parent
3ea6fbc
commit 2f1634e
Showing
109 changed files
with
34,160 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package thorchain | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
|
||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
grpc "google.golang.org/grpc" | ||
"google.golang.org/grpc/metadata" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" | ||
) | ||
|
||
var ( | ||
_ client.Account = sdk.AccountI(nil) | ||
_ client.AccountRetriever = AccountRetriever{} | ||
) | ||
|
||
// AccountRetriever defines the properties of a type that can be used to | ||
// retrieve accounts. | ||
type AccountRetriever struct { | ||
chain *Thorchain | ||
} | ||
|
||
// GetAccount queries for an account given an address and a block height. An | ||
// error is returned if the query or decoding fails. | ||
func (ar AccountRetriever) GetAccount(clientCtx client.Context, addr sdk.AccAddress) (client.Account, error) { | ||
account, _, err := ar.GetAccountWithHeight(clientCtx, addr) | ||
return account, err | ||
} | ||
|
||
// GetAccountWithHeight queries for an account given an address. Returns the | ||
// height of the query with the account. An error is returned if the query | ||
// or decoding fails. | ||
func (ar AccountRetriever) GetAccountWithHeight(clientCtx client.Context, addr sdk.AccAddress) (client.Account, int64, error) { | ||
var header metadata.MD | ||
|
||
bech32Address, err := ar.chain.AccAddressToBech32(addr) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
queryClient := authtypes.NewQueryClient(clientCtx) | ||
res, err := queryClient.Account(context.Background(), &authtypes.QueryAccountRequest{Address: bech32Address}, grpc.Header(&header)) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader) | ||
if l := len(blockHeight); l != 1 { | ||
return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected: %d", grpctypes.GRPCBlockHeightHeader, l, 1) | ||
} | ||
|
||
nBlockHeight, err := strconv.Atoi(blockHeight[0]) | ||
if err != nil { | ||
return nil, 0, fmt.Errorf("failed to parse block height: %w", err) | ||
} | ||
|
||
var acc sdk.AccountI | ||
if err := clientCtx.InterfaceRegistry.UnpackAny(res.Account, &acc); err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
return acc, int64(nBlockHeight), nil | ||
} | ||
|
||
// EnsureExists returns an error if no account exists for the given address else nil. | ||
func (ar AccountRetriever) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error { | ||
if _, err := ar.GetAccount(clientCtx, addr); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetAccountNumberSequence returns sequence and account number for the given address. | ||
// It returns an error if the account couldn't be retrieved from the state. | ||
func (ar AccountRetriever) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) { | ||
acc, err := ar.GetAccount(clientCtx, addr) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
|
||
return acc.GetAccountNumber(), acc.GetSequence(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package thorchain | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/bech32" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// AccAddressFromBech32 creates an AccAddress from a Bech32 string. | ||
// https://github.com/cosmos/cosmos-sdk/blob/v0.50.2/types/address.go#L193-L212 | ||
func (c *Thorchain) AccAddressFromBech32(address string) (addr sdk.AccAddress, err error) { | ||
if len(strings.TrimSpace(address)) == 0 { | ||
return sdk.AccAddress{}, errors.New("empty address string is not allowed") | ||
} | ||
|
||
bz, err := sdk.GetFromBech32(address, c.Config().Bech32Prefix) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = sdk.VerifyAddressFormat(bz) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return sdk.AccAddress(bz), nil | ||
} | ||
|
||
func (c *Thorchain) AccAddressToBech32(addr sdk.AccAddress) (string, error) { | ||
return bech32.ConvertAndEncode(c.Config().Bech32Prefix, addr) | ||
} |
Oops, something went wrong.