Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/runtime.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@ package account_nonce
import (
"bytes"

"github.com/LimeChain/gosemble/frame/system"
"github.com/LimeChain/gosemble/frame/system/module"
"github.com/LimeChain/gosemble/primitives/types"
"github.com/LimeChain/gosemble/utils"
)

type Module struct {
systemModule module.SystemModule
}

func New(systemModule module.SystemModule) Module {
return Module{systemModule}
}

// AccountNonce returns the account nonce of given AccountId.
// It takes two arguments:
// - dataPtr: Pointer to the data in the Wasm memory.
// - dataLen: Length of the data.
// which represent the SCALE-encoded AccountId.
// Returns a pointer-size of the SCALE-encoded nonce of the AccountId.
// [Specification](https://spec.polkadot.network/chap-runtime-api#sect-accountnonceapi-account-nonce)
func AccountNonce(dataPtr int32, dataLen int32) int64 {
func (m Module) AccountNonce(dataPtr int32, dataLen int32) int64 {
b := utils.ToWasmMemorySlice(dataPtr, dataLen)
buffer := bytes.NewBuffer(b)

publicKey := types.DecodePublicKey(buffer)
nonce := system.StorageGetAccount(publicKey).Nonce
nonce := m.systemModule.Get(publicKey).Nonce

return utils.BytesToOffsetAndSize(nonce.Bytes())
}
22 changes: 0 additions & 22 deletions frame/system/storage.go

This file was deleted.

3 changes: 2 additions & 1 deletion runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ func AuraApiAuthorities(_, _ int32) int64 {

//go:export AccountNonceApi_account_nonce
func AccountNonceApiAccountNonce(dataPtr int32, dataLen int32) int64 {
return account_nonce.AccountNonce(dataPtr, dataLen)
return account_nonce.New(modules[SystemIndex].(sm.SystemModule)).
AccountNonce(dataPtr, dataLen)
}

//go:export TransactionPaymentApi_query_info
Expand Down