Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Sep 4, 2024
1 parent 8cb127e commit 2df1f54
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ func (m WasmAppModuleBasicOverride) DefaultGenesis(cdc codec.JSONCodec) json.Raw
})
}

// QueryRequest is the custom queries wasm contracts can make for the core modules
type QueryRequest struct {
Nexus *nexus.WasmQueryRequest
}

// NewQueryPlugins returns a new instance of the custom query plugins
func NewQueryPlugins(txIDGenerator nexustypes.TxIDGenerator) *wasmkeeper.QueryPlugins {
nexusWasmQuerier := nexusKeeper.NewWasmQuerier(txIDGenerator)

Expand Down
6 changes: 4 additions & 2 deletions x/nexus/exported/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,13 @@ func (bz *WasmBytes) UnmarshalJSON(data []byte) error {
return nil
}

// WasmQueryRequest is the request for wasm contracts to query
type WasmQueryRequest struct {
TxID *struct{} `json:"tx_id,omitempty"`
}

// WasmQueryTxIDResponse is the response for the TxID query
type WasmQueryTxIDResponse struct {
TxHash [32]byte `json:"tx_hash,omitempty"`
Index uint64 `json:"index,omitempty"`
TxHash [32]byte `json:"tx_hash,omitempty"` // the hash of the current transaction
Index uint64 `json:"index,omitempty"` // the index of the current execution, which increments with each entry of any wasm execution
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package keeper
import (
"crypto/sha256"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/axelarnetwork/axelar-core/utils"
"github.com/axelarnetwork/axelar-core/x/nexus/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ types.TxIDGenerator = &Keeper{}
Expand All @@ -14,10 +15,12 @@ func getTxHash(ctx sdk.Context) [32]byte {
return sha256.Sum256(ctx.TxBytes())
}

// Next returns the next transaction hash and index, and increments the index
func (k Keeper) Next(ctx sdk.Context) ([32]byte, uint64) {
return getTxHash(ctx), utils.NewCounter[uint64](messageNonceKey, k.getStore(ctx)).Incr(ctx)
}

// Curr returns the current transaction hash and index
func (k Keeper) Curr(ctx sdk.Context) ([32]byte, uint64) {
return getTxHash(ctx), utils.NewCounter[uint64](messageNonceKey, k.getStore(ctx)).Curr(ctx)

Check warning on line 25 in x/nexus/keeper/tx_id_generator.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/tx_id_generator.go#L24-L25

Added lines #L24 - L25 were not covered by tests
}
3 changes: 3 additions & 0 deletions x/nexus/keeper/wasm_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
"github.com/axelarnetwork/utils/funcs"
)

// WasmQuerier is a querier for the wasm contracts
type WasmQuerier struct {
txIDGenerator types.TxIDGenerator
}

// NewWasmQuerier creates a new WasmQuerier
func NewWasmQuerier(txIDGenerator types.TxIDGenerator) *WasmQuerier {
return &WasmQuerier{txIDGenerator}

Check warning on line 21 in x/nexus/keeper/wasm_querier.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasm_querier.go#L20-L21

Added lines #L20 - L21 were not covered by tests
}

// Query handles the wasm queries for the nexus module
func (q WasmQuerier) Query(ctx sdk.Context, req exported.WasmQueryRequest) ([]byte, error) {
if req.TxID != nil {
txHash, index := q.txIDGenerator.Curr(ctx)

Check warning on line 27 in x/nexus/keeper/wasm_querier.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasm_querier.go#L25-L27

Added lines #L25 - L27 were not covered by tests
Expand Down
10 changes: 9 additions & 1 deletion x/nexus/keeper/wasmer_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/axelarnetwork/axelar-core/x/nexus/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/axelarnetwork/axelar-core/x/nexus/types"
)

// WasmerEngine is a wrapper around the WasmerEngine to add a transaction ID generator
type WasmerEngine struct {
wasmtypes.WasmerEngine
txIDGenerator types.TxIDGenerator
}

// NewWasmerEngine wraps the given engine with a transaction ID generator
func NewWasmerEngine(inner wasmtypes.WasmerEngine, txIDGenerator types.TxIDGenerator) wasmtypes.WasmerEngine {
return &WasmerEngine{WasmerEngine: inner, txIDGenerator: txIDGenerator}

Check warning on line 21 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L20-L21

Added lines #L20 - L21 were not covered by tests
}
Expand All @@ -22,6 +25,7 @@ func getCtx(querier wasmvm.Querier) sdk.Context {
return querier.(wasmkeeper.QueryHandler).Ctx

Check warning on line 25 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L24-L25

Added lines #L24 - L25 were not covered by tests
}

// Instantiate calls the inner engine and increments the transaction ID
func (w *WasmerEngine) Instantiate(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
Expand All @@ -39,6 +43,7 @@ func (w *WasmerEngine) Instantiate(
return w.WasmerEngine.Instantiate(checksum, env, info, initMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 43 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L43

Added line #L43 was not covered by tests
}

// Execute calls the inner engine and increments the transaction ID
func (w *WasmerEngine) Execute(
code wasmvm.Checksum,
env wasmvmtypes.Env,
Expand All @@ -56,6 +61,7 @@ func (w *WasmerEngine) Execute(
return w.WasmerEngine.Execute(code, env, info, executeMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 61 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L61

Added line #L61 was not covered by tests
}

// Migrate calls the inner engine and increments the transaction ID
func (w *WasmerEngine) Migrate(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
Expand All @@ -72,6 +78,7 @@ func (w *WasmerEngine) Migrate(
return w.WasmerEngine.Migrate(checksum, env, migrateMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 78 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L78

Added line #L78 was not covered by tests
}

// Sudo calls the inner engine and increments the transaction ID
func (w *WasmerEngine) Sudo(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
Expand All @@ -88,6 +95,7 @@ func (w *WasmerEngine) Sudo(
return w.WasmerEngine.Sudo(checksum, env, sudoMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 95 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L95

Added line #L95 was not covered by tests
}

// Reply calls the inner engine and increments the transaction ID
func (w *WasmerEngine) Reply(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
Expand Down

0 comments on commit 2df1f54

Please sign in to comment.