-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Off-chain] refactor: keyring errors & helpers (#131)
* chore: add `TxClient` interface * chore: add option support to `ReplayObservable` * feat: add `txClient` implementation * test: `txClient` * test: tx client integration * chore: s/tx/transaction/g * chore: update pkg README.md template * wip: client pkg README * docs: fix client pkg godoc comment * refactor: consolidate keyring errors & helpers * refactor: keyring test helpers * fix: flakey test * chore: dial back godoc comments 😅 * chore: revise (and move to godoc.go) `testblock` & `testeventsquery` pkg godoc comment * chore: update go.mod * chore: refactor & condense godoc comments * chore: fix import paths post-update
- Loading branch information
1 parent
1974c8a
commit aecdf18
Showing
8 changed files
with
94 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package testkeyring | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
|
||
"github.com/pokt-network/poktroll/internal/testclient" | ||
) | ||
|
||
// NewTestKeyringWithKey creates a new in-memory keyring with a test key | ||
// with testSigningKeyName as its name. | ||
func NewTestKeyringWithKey(t *testing.T, keyName string) (keyring.Keyring, *keyring.Record) { | ||
keyring := keyring.NewInMemory(testclient.EncodingConfig.Marshaler) | ||
key, _ := testclient.NewKey(t, keyName, keyring) | ||
return keyring, key | ||
} |
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,19 @@ | ||
package keyring | ||
|
||
import "cosmossdk.io/errors" | ||
|
||
var ( | ||
// ErrEmptySigningKeyName represents an error which indicates that the | ||
// provided signing key name is empty or unspecified. | ||
ErrEmptySigningKeyName = errors.Register(codespace, 1, "empty signing key name") | ||
|
||
// ErrNoSuchSigningKey represents an error signifying that the requested | ||
// signing key does not exist or could not be located. | ||
ErrNoSuchSigningKey = errors.Register(codespace, 2, "signing key does not exist") | ||
|
||
// ErrSigningKeyAddr is raised when there's a failure in retrieving the | ||
// associated address for the provided signing key. | ||
ErrSigningKeyAddr = errors.Register(codespace, 3, "failed to get address for signing key") | ||
|
||
codespace = "keyring" | ||
) |
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,29 @@ | ||
package keyring | ||
|
||
import ( | ||
cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
cosmostypes "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// KeyNameToAddr attempts to retrieve the key with the given name from the | ||
// given keyring and compute its address. | ||
func KeyNameToAddr( | ||
keyName string, | ||
keyring cosmoskeyring.Keyring, | ||
) (cosmostypes.AccAddress, error) { | ||
if keyName == "" { | ||
return nil, ErrEmptySigningKeyName | ||
} | ||
|
||
keyRecord, err := keyring.Key(keyName) | ||
if err != nil { | ||
return nil, ErrNoSuchSigningKey.Wrapf("name %q: %s", keyName, err) | ||
} | ||
|
||
signingAddr, err := keyRecord.GetAddress() | ||
if err != nil { | ||
return nil, ErrSigningKeyAddr.Wrapf("name %q: %s", keyName, err) | ||
} | ||
|
||
return signingAddr, 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
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