-
Notifications
You must be signed in to change notification settings - Fork 1
/
state.go
85 lines (73 loc) · 3.24 KB
/
state.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
package state
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/freeverseio/laos-universal-node/internal/platform/model"
"github.com/freeverseio/laos-universal-node/internal/platform/state/tree/account"
)
// Service interface is used for initializing and terminating state transaction.
type Service interface {
NewTransaction() (Tx, error)
}
// Tx interface wraps all the available actions for state
type Tx interface {
Discard()
Commit() error
State
OwnershipContractState
EvolutionContractState
OwnershipSyncState
EvolutionSyncState
}
// State interface defines functions to interact with state of the blockchain
type State interface {
OwnerOf(contract common.Address, tokenId *big.Int) (common.Address, error)
BalanceOf(contract, owner common.Address) (*big.Int, error)
TokenOfOwnerByIndex(contract, owner common.Address, idx int) (*big.Int, error)
TotalSupply(contract common.Address) (int64, error)
TokenByIndex(contract common.Address, idx int) (*big.Int, error)
TokenURI(contract common.Address, tokenId *big.Int) (string, error)
Transfer(contract common.Address, eventTransfer *model.ERC721Transfer) error
Mint(contract common.Address, mintEvent *model.MintedWithExternalURI) error
LoadContractTrees(contractAddress common.Address) error
UpdateContractState(contract common.Address, lastProcessedEvoBlock uint64) error
AccountData(contract common.Address) (*account.AccountData, error)
TagRoot(blockNumber int64) error
DeleteOrphanRootTags(formBlock, toBlock int64) error
GetLastTaggedBlock() (int64, error)
Checkout(blockNumber int64) error
}
type OwnershipContractState interface {
StoreERC721UniversalContracts(universalContracts []model.ERC721UniversalContract) error
GetExistingERC721UniversalContracts(contracts []string) ([]string, error)
GetCollectionAddress(contract string) (common.Address, error)
GetAllERC721UniversalContracts() []string
HasERC721UniversalContract(contract string) (bool, error)
}
type EvolutionContractState interface {
GetMintedWithExternalURIEvents(contract string, blockNumber uint64) ([]model.MintedWithExternalURI, error)
StoreMintedWithExternalURIEvent(contract string, event *model.MintedWithExternalURI) error
}
type OwnershipSyncState interface {
SetFirstOwnershipBlock(block model.Block) error
GetFirstOwnershipBlock() (model.Block, error)
SetLastOwnershipBlock(block model.Block) error
GetLastOwnershipBlock() (model.Block, error)
GetOwnershipBlock(blockNumber uint64) (model.Block, error)
SetOwnershipBlock(blockNumber uint64, block model.Block) error
GetAllStoredBlockNumbers() ([]uint64, error)
DeleteOldStoredBlockNumbers() error
DeleteOrphanBlockData(blockNumberRef uint64) error
SetLastMappedOwnershipBlockNumber(blockNumber uint64) error
GetLastMappedOwnershipBlockNumber() (uint64, error)
SetOwnershipEvoBlockMapping(ownershipBlockNumber, evoBlockNumber uint64) error
GetMappedEvoBlockNumber(ownershipBlockNumber uint64) (uint64, error)
}
type EvolutionSyncState interface {
SetNextEvoEventBlock(contract string, blockNumber uint64) error
GetNextEvoEventBlock(contract string, blockNumber uint64) (uint64, error)
SetFirstEvoBlock(block model.Block) error
GetFirstEvoBlock() (model.Block, error)
SetLastEvoBlock(block model.Block) error
GetLastEvoBlock() (model.Block, error)
}