Skip to content

Commit

Permalink
docs: add comments and modify readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonyongjung committed Sep 8, 2023
1 parent 562db26 commit 3cf51c7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Xpla.go is a Golang SDK for writing applications that interact with the Xpla blo

|xpla.go|XPLA|Note|
|:---:|:---:|:---:|
|v0.1.1|[v1.2.3](https://github.com/xpladev/xpla/tree/v1.2.3)||
|v0.1.1-v0.1.2|[v1.2.3](https://github.com/xpladev/xpla/tree/v1.2.3)||
|v0.1.0|[v1.2.2](https://github.com/xpladev/xpla/tree/v1.2.2)||


Expand Down
7 changes: 7 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ package core
import cmclient "github.com/cosmos/cosmos-sdk/client"

// The standard form for a module in the core package.
// Every modules are enrolled to the controller by using this interface.
type CoreModule interface {
// Name of a core module must not be duplicated previous names.
Name() string

// Routed transaction messages are built in the TxBuilder of Cosmos-SDK.
NewTxRouter(cmclient.TxBuilder, string, interface{}) (cmclient.TxBuilder, error)

// Route query requests by gRPC or HTTP.
// Queries are returned with string type regardless of communication protocol.
NewQueryRouter(QueryClient) (string, error)
}
40 changes: 39 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,35 @@ import (
)

// The standard form of XPLA client is interface type.
// XplaClient is endpoint in order to access xpla.go from external packages.
// If new modules are implemeted, external functions that are used to send tx or query state should be
// enrolled in XplaClient interface.
//
// e.g. - enroll bank module
//
// type TxMsgProvider interface {
// ...
// BankSend(types.BankSendMsg) XplaClient
// ...
// }
//
// type QueryMsgProvider interface {
// ...
// BankBalances(types.BankBalancesMsg) XplaClient
// DenomMetadata(...types.DenomMetadataMsg) XplaClient
// Total(...types.TotalMsg) XplaClient
// ...
// }
//
// The return type of these methods must be always the XplaClient because the client uses mehod chaining.
//
// e.g. - create and sign transaction
//
// txbytes, err := xplac.BankSend(bankSendMsg).CreateAndSignTx()
//
// e.g. - query
//
// res, err := xplac.BankBalances(bankBalancesMsg).Query()
type XplaClient interface {
WithProvider
GetProvider
Expand All @@ -29,7 +58,7 @@ type XplaClient interface {
HelperProvider
}

// Optional parameters of xpla client.
// Optional parameters of client.xplaClient.
type Options struct {
PrivateKey key.PrivateKey
AccountNumber string
Expand All @@ -50,6 +79,7 @@ type Options struct {
OutputDocument string
}

// Methods set params of client.xplaClient.
type WithProvider interface {
UpdateXplacInCoreModule() XplaClient
WithOptions(Options) XplaClient
Expand Down Expand Up @@ -79,6 +109,7 @@ type WithProvider interface {
WithErr(err error) XplaClient
}

// Methods get params of client.xplaClient.
type GetProvider interface {
GetChainId() string
GetPrivateKey() key.PrivateKey
Expand Down Expand Up @@ -107,6 +138,7 @@ type GetProvider interface {
GetErr() error
}

// Methods handle transaction.
type TxProvider interface {
CreateAndSignTx() ([]byte, error)
CreateUnsignedTx() ([]byte, error)
Expand All @@ -117,21 +149,25 @@ type TxProvider interface {
ValidateSignatures(types.ValidateSignaturesMsg) (string, error)
}

// Method handles query functions.
type QueryProvider interface {
Query() (string, error)
}

// Methods handle functions of broadcasting.
type BroadcastProvider interface {
Broadcast([]byte) (*types.TxRes, error)
BroadcastBlock([]byte) (*types.TxRes, error)
BroadcastAsync([]byte) (*types.TxRes, error)
}

// Methods get information from XPLA chain.
type InfoRequestProvider interface {
LoadAccount(sdk.AccAddress) (authtypes.AccountI, error)
Simulate(cmclient.TxBuilder) (*sdktx.SimulateResponse, error)
}

// Methods are external functions of each module for sending transaction.
type TxMsgProvider interface {
// authz
AuthzGrant(types.AuthzGrantMsg) XplaClient
Expand Down Expand Up @@ -195,6 +231,7 @@ type TxMsgProvider interface {
Migrate(types.MigrateMsg) XplaClient
}

// Methods are external functions of each module for querying.
type QueryMsgProvider interface {
// auth
AuthParams() XplaClient
Expand Down Expand Up @@ -339,6 +376,7 @@ type QueryMsgProvider interface {
LibwasmvmVersion() XplaClient
}

// Method of helper.
type HelperProvider interface {
EncodedTxbytesToJsonTx([]byte) ([]byte, error)
}
3 changes: 3 additions & 0 deletions provider/provider_helper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package provider

// Reset XplaClient.
// Remove recorded all parameters.
func ResetXplac(xplac XplaClient) XplaClient {
return ResetModuleAndMsgXplac(xplac).
WithOptions(Options{}).
WithErr(nil)
}

// Reset XplaClient with removing module name and message.
func ResetModuleAndMsgXplac(xplac XplaClient) XplaClient {
return xplac.
WithModule("").
Expand Down
3 changes: 2 additions & 1 deletion util/testutil/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)

// RandomAccounts generates n random accounts
// RandomAccounts generates n random accounts.
func RandomAccounts(r *rand.Rand, n int) []simtypes.Account {
accs := make([]simtypes.Account, n)

Expand All @@ -30,6 +30,7 @@ func RandomAccounts(r *rand.Rand, n int) []simtypes.Account {
return accs
}

// RandomSecp256k1Accounts is prepared func for test.
func RandomSecp256k1Accounts(r *rand.Rand, n int) []simtypes.Account {
accs := make([]simtypes.Account, n)

Expand Down

0 comments on commit 3cf51c7

Please sign in to comment.