1
1
import { Address } from "./address" ;
2
2
import { Assert } from "./system" ;
3
3
import { RIPEMD160_LEN , SHA256_LEN , SHA512_LEN } from "../lib/constant" ;
4
- import { getActionName , getActionData , hasAuth , requireAuth , callAction , returnData , returnU64 } from "../internal/action.d" ;
4
+ import { getActionName , getActionData , hasAuth , requireAuth , callAction , returnData , returnU64 , getValue } from "../internal/action.d" ;
5
5
import { BytesToString , EncodeSLEB128 , EncodeULEB128 , StringToBytes , StringToUsize } from "../lib/codec" ;
6
6
import { U8ArrayToBytes , CreateDataStream , BytesToU8Array , } from "../lib/helper" ;
7
- import { Asset } from "./asset" ;
7
+ import { Asset , UNIT } from "./asset" ;
8
8
9
9
/**
10
10
* Builtin represents a parameter with built-in type.
@@ -131,25 +131,18 @@ export class Builtin implements Serializable {
131
131
/**
132
132
* BuiltinArray represents an array of parameters with built-in types,
133
133
* like 'string[]', 'u64[]'
134
+ *
134
135
*/
135
- export class BuiltinArray extends Builtin implements Serializable {
136
- _params : Builtin [ ]
137
-
138
- constructor ( params : Builtin [ ] ) {
139
- super ( new Bytes ( 0 ) ) ;
140
- this . _params = params ;
141
- }
142
-
143
- len ( ) : i32 {
144
- return this . _params . length
145
- }
146
-
136
+ export class BuiltinArray extends Array < Builtin > implements Serializable {
147
137
serialize ( ds : DataStream ) : void {
148
- ds . writeComplexVector < Builtin > ( this . _params ) ;
138
+ ds . writeComplexVector < Builtin > ( this ) ;
149
139
}
150
140
151
141
deserialize ( ds : DataStream ) : void {
152
- this . _params = ds . readComplexVector < Builtin > ( ) ;
142
+ const arr = ds . readComplexVector < Builtin > ( ) ;
143
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
144
+ this . push ( arr [ i ] ) ;
145
+ }
153
146
}
154
147
155
148
key ( ) : string {
@@ -186,6 +179,14 @@ export class Action implements Serializable {
186
179
return ds ;
187
180
}
188
181
182
+ static getValue ( ) : Asset {
183
+ const size = getValue ( 0 , 0 ) ;
184
+ const ds = CreateDataStream ( size ) ;
185
+ getValue ( ds . buffer , ds . len ) ;
186
+ const amount = ds . read < u64 > ( ) ;
187
+ return new Asset ( amount , UNIT ) ;
188
+ }
189
+
189
190
send ( ) : void {
190
191
Assert ( this . _method != "__DEPLOY__" , "action name should not be '__DEPLOY__'" ) ;
191
192
const size = DataStream . measure < Action > ( this ) ;
@@ -201,7 +202,7 @@ export class Action implements Serializable {
201
202
this . _value . serialize ( ds ) ;
202
203
// fill the method of action
203
204
ds . writeString ( this . _method ) ;
204
- let payloadSize = 0 ;
205
+ let payloadSize : u64 = 0 ;
205
206
// fill serialized payload field
206
207
for ( let i = 0 ; i < this . _payload . length ; i ++ ) {
207
208
const param = this . _payload [ i ] ;
@@ -213,6 +214,7 @@ export class Action implements Serializable {
213
214
throw new Error ( "unknown parameters type" ) ;
214
215
}
215
216
}
217
+ ds . write < u64 > ( payloadSize ) ;
216
218
for ( let i = 0 ; i < this . _payload . length ; i ++ ) {
217
219
this . _payload [ i ] . serialize ( ds ) ;
218
220
}
0 commit comments