-
Notifications
You must be signed in to change notification settings - Fork 14
/
stateChanges.ts
90 lines (74 loc) · 2.86 KB
/
stateChanges.ts
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
import { StateChangeWithCauseView } from './core/types';
import { AccessKey } from './receipts';
/**
* This structure is almost an identical copy of the `StateChangeWithCauseView` from [near-primitives](https://github.com/near/nearcore/tree/master/core/primitives) with a propagated additional field `affectedAccountId`.
*/
export class StateChange {
constructor(
/**
* Returns the `cause` of the `StateChange`.
*/
readonly cause: StateChangeCause,
/**
* Returns the `value` of the `StateChange`.
*/
readonly value: StateChangeValue) {}
/**
* Returns the account id of the `StateChange`.
*/
get affectedAccountId(): string {
return this.value.accountId;
}
/**
* Returns the `StateChange` from the `StateChangeWithCauseView`. Created for backward compatibility.
*/
static fromStateChangeView(stateChangeView: StateChangeWithCauseView) {
let { cause, value } = stateChangeView;
return new StateChange(cause, value)
}
}
type TransactionProcessingCause = { txHash: string };
type ActionReceiptProcessingStartedCause = { receiptHash: string }
type ActionReceiptGasRewardCause = { receiptHash: string }
type ReceiptProcessingCause = { receiptHash: string }
type PostponedReceiptCause = { receiptHash: string }
type StateChangeCause =
'NotWritableToDisk' |
'InitialState' |
TransactionProcessingCause |
ActionReceiptProcessingStartedCause |
ActionReceiptGasRewardCause |
ReceiptProcessingCause |
PostponedReceiptCause |
'UpdatedDelayedReceipts' |
'ValidatorAccountsUpdate' |
'Migration' |
'Resharding'
class AccountUpdateValue {
constructor(readonly accountId: string, readonly account: Account) {}
}
class AccountDeletionValue {
constructor(readonly accountId: string) {}
}
class AccountKeyUpdateValue {
constructor(readonly accountId: string, readonly publicKey: string, readonly accessKey: AccessKey) {}
}
class AccessKeyDeletionValue {
constructor(readonly accountId: string, readonly publicKey: string) {}
}
class DataUpdateValue {
constructor(readonly accountId: string, readonly key: Uint8Array, readonly value: Uint8Array) {}
}
class DataDeletionValue {
constructor(readonly accountId: string, readonly key: Uint8Array) {}
}
class ContractCodeUpdateValue {
constructor(readonly accountId: string, readonly code: Uint8Array) {}
}
class ContractCodeDeletionValue {
constructor(readonly accountId: string) {}
}
type StateChangeValue = AccountUpdateValue | AccountDeletionValue | AccountKeyUpdateValue | AccessKeyDeletionValue | DataUpdateValue | DataDeletionValue | ContractCodeUpdateValue | ContractCodeDeletionValue
class Account {
constructor(readonly amount: number, readonly locked: number, readonly codeHash: string, readonly storageUsage: number, readonly storagePaidAt: number) {}
}