-
Notifications
You must be signed in to change notification settings - Fork 3
/
System.d.ts
executable file
·216 lines (174 loc) · 6.72 KB
/
System.d.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import BigNumber from './bignumber';
interface Descriptor {
// serialize value to string;
stringify?(value: any): string;
// deserialize value from string;
parse?(value: string): any;
}
interface DescriptorMap {
[fieldName: string]: Descriptor | null;
}
interface ContractStorage {
// get and return value by key from Native Storage.
rawGet(key: string): string;
// set key and value pair to Native Storage,
// return 0 for success, otherwise failure.
rawSet(key: string, value: string): number;
// define a object property named `fieldname` to `obj` with descriptor.
// default descriptor is JSON.parse/JSON.stringify descriptor.
// return this.
defineProperty(obj: any, fieldName: string, descriptor?: Descriptor): any;
// define object properties to `obj` from `props`.
// default descriptor is JSON.parse/JSON.stringify descriptor.
// return this.
defineProperties(obj: any, props: DescriptorMap): any;
// define a StorageMap property named `fieldname` to `obj` with descriptor.
// default descriptor is JSON.parse/JSON.stringify descriptor.
// return this.
defineMapProperty(obj: any, fieldName: string, descriptor?: Descriptor): any;
// define StorageMap properties to `obj` from `props`.
// default descriptor is JSON.parse/JSON.stringify descriptor.
// return this.
defineMapProperties(obj: any, props: DescriptorMap): any;
// delete key from Native Storage.
// return 0 for success, otherwise failure.
del(key: string): number;
// get value by key from Native Storage,
// deserialize value by calling `descriptor.parse` and return.
get(key: string): any;
// set key and value pair to Native Storage,
// the value will be serialized to string by calling `descriptor.stringify`.
// return 0 for success, otherwise failure.
set(key: string, value: any): number;
}
//用于编写代码时的提示
export declare const LocalContractStorage: ContractStorage;
export interface StorageMap<T> {
// delete key from Native Storage, return 0 for success, otherwise failure.
del(key: string): number;
// get value by key from Native Storage,
// deserialize value by calling `descriptor.parse` and return.
get(key: string): T;
// set key and value pair to Native Storage,
// the value will be serialized to string by calling `descriptor.stringify`.
// return 0 for success, otherwise failure.
set(key: string, value: any): number;
}
//blockchain结构,根据官方文档yy的
interface DynamicParameter {
[fieldName: string]: any;
}
interface IBlockchain {
// current block
block: {
//块的时间戳,单位:?
timestamp: number;
//随机数种子
seed: any;
//区块高度
height: number;
};
// current transaction, transaction's value/gasPrice/gasLimit auto change to BigNumber object
transaction: {
hash: string; //交易哈希
from: string; //交易发送地址
to: string; //交易目的地址
value: BigNumber; //交易金额, 一个BigNumber对象
nonce: number; //交易nonce
timestamp: number; //交易时间戳,单位:?
gasPrice: BigNumber; //gas出价, 一个BigNumber对象
gasLimit: BigNumber; //gas上限值, 一个BigNumber对象
}
// transfer NAS from contract to address
transfer(address: string, value: BigNumber): boolean;
// verify address
// 返回值:
// 87: 用户钱包地址
// 88: 合约地址
// 0: 地址非法
verifyAddress(address: string): 87 | 88 | 0;
getAccountState(address: string): {
balance: BigNumber | number | string,
nonce: BigNumber | number | string
}
}
//代码提示用
export declare const Blockchain: IBlockchain;
//Event,根据官方文档yy的
interface IEvent {
Trigger(topic: string, jsonObj: Object): void;
}
//代码提示用
export declare const Event: IEvent;
// //math库,根据官方文档yy的
// class Math {
// //随机范围[0,1)
// public static get random():(()=>void) & {seed:(seed:string)=>void} {
// return null;
// };
// }
// Date:
// 不支持的方法:toDateString(), toTimeString(), getTimezoneOffset(), toLocaleXXX()。
// new Date()/Date.now()返回当前块的时间戳,单位为毫秒。
// getXXX返回getUTCXXX的结果。
//-----------------------------以下为需参与编译的代码----------------------------------
// //地址类型
// type Address = string;
// // //字典类型
// // interface Dic<TValue> {
// // [fieldName: string]: TValue;
// // }
// //便于使用的map interface
// interface MyStorageMap<TValue> {
// // delete key from Native Storage, return 0 for success, otherwise failure.
// del(key: string): number;
// // get value by key from Native Storage,
// // deserialize value by calling `descriptor.parse` and return.
// get(key: string): TValue;
// // set key and value pair to Native Storage,
// // the value will be serialized to string by calling `descriptor.stringify`.
// // return 0 for success, otherwise failure.
// set(key: string, value: TValue): number;
// }
// /**
// * 断言
// * @param result 比较结果
// * @param reason 断言失败的原因
// */
// function assert(result:boolean, reason?:string){
// if(!reason){
// reason = 'no reason';
// }
// if(!result){
// throw new Error(reason);
// }
// }
// /**
// * 从arrayMap中获取分页数据
// * @param arrMap
// * @param startIndex 数组的起始位置,默认为0
// * @param totalLength 数组长度
// * @param offset
// * @param limit
// * @param desc 是否降序
// */
// function getDatasFromArrayMap<TDataType>(arrMap:MyStorageMap<TDataType>, startIndex:number, totalLength:number, offset:number, limit: number, desc:boolean){
// //计算出最大页数
// assert(offset < totalLength, `offset is out of range, total:${totalLength}`);
// const items:TDataType[] = [];
// //按照顺序依次获取
// if(!desc){
// for(let i=startIndex+offset; i<=startIndex+offset+limit-1; i++){
// if(i>startIndex+totalLength-1){break;}
// const item = arrMap.get(i.toString());
// items.push(item);
// }
// }else{
// for(let i=startIndex+totalLength-1-offset; i>= startIndex+totalLength-1-offset-limit+1; i--){
// if(i<1){break;}
// const item = arrMap.get(i.toString());
// items.push(item);
// }
// }
// return items;
// }