forked from ChainSafe/gossamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
96 lines (87 loc) · 3.38 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2019 ChainSafe Systems (ON) Corp.
// This file is part of gossamer.
//
// The gossamer library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The gossamer library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.
package runtime
import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/common/optional"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/lib/trie"
)
// Instance is the interface a v0.8 runtime instance must implement
type Instance interface {
UpdateRuntimeCode([]byte) error
CheckRuntimeVersion([]byte) (Version, error)
Stop()
NodeStorage() NodeStorage
NetworkService() BasicNetwork
Keystore() *keystore.GlobalKeystore
Validator() bool
Exec(function string, data []byte) ([]byte, error)
SetContextStorage(s Storage) // used to set the TrieState before a runtime call
GetCodeHash() common.Hash
Version() (Version, error)
Metadata() ([]byte, error)
BabeConfiguration() (*types.BabeConfiguration, error)
GrandpaAuthorities() ([]types.Authority, error)
ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)
InitializeBlock(header *types.Header) error
InherentExtrinsics(data []byte) ([]byte, error)
ApplyExtrinsic(data types.Extrinsic) ([]byte, error)
FinalizeBlock() (*types.Header, error)
ExecuteBlock(block *types.Block) ([]byte, error)
DecodeSessionKeys(enc []byte) ([]byte, error)
// TODO: parameters and return values for these are undefined in the spec
CheckInherents()
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
}
// Storage interface
type Storage interface {
Set(key []byte, value []byte)
Get(key []byte) []byte
Root() (common.Hash, error)
SetChild(keyToChild []byte, child *trie.Trie) error
SetChildStorage(keyToChild, key, value []byte) error
GetChildStorage(keyToChild, key []byte) ([]byte, error)
Delete(key []byte)
DeleteChild(keyToChild []byte)
DeleteChildLimit(keyToChild []byte, limit *optional.Bytes) (uint32, bool, error)
ClearChildStorage(keyToChild, key []byte) error
NextKey([]byte) []byte
ClearPrefixInChild(keyToChild, prefix []byte) error
GetChildNextKey(keyToChild, key []byte) ([]byte, error)
GetChild(keyToChild []byte) (*trie.Trie, error)
ClearPrefix(prefix []byte) error
BeginStorageTransaction()
CommitStorageTransaction()
RollbackStorageTransaction()
}
// BasicNetwork interface for functions used by runtime network state function
type BasicNetwork interface {
NetworkState() common.NetworkState
}
// BasicStorage interface for functions used by runtime offchain workers
type BasicStorage interface {
Put(key []byte, value []byte) error
Get(key []byte) ([]byte, error)
}
// TransactionState interface for adding transactions to pool
type TransactionState interface {
AddToPool(vt *transaction.ValidTransaction) common.Hash
}