@@ -8997,14 +8997,20 @@ export class NativeScriptSource {
8997
8997
export class NativeScripts {
8998
8998
private items : NativeScript [ ] ;
8999
8999
private definiteEncoding : boolean ;
9000
+ private nonEmptyTag : boolean ;
9000
9001
9001
- constructor ( items : NativeScript [ ] , definiteEncoding : boolean = true ) {
9002
+ private setItems ( items : NativeScript [ ] ) {
9002
9003
this . items = items ;
9004
+ }
9005
+
9006
+ constructor ( definiteEncoding : boolean = true , nonEmptyTag : boolean = true ) {
9007
+ this . items = [ ] ;
9003
9008
this . definiteEncoding = definiteEncoding ;
9009
+ this . nonEmptyTag = nonEmptyTag ;
9004
9010
}
9005
9011
9006
9012
static new ( ) : NativeScripts {
9007
- return new NativeScripts ( [ ] ) ;
9013
+ return new NativeScripts ( ) ;
9008
9014
}
9009
9015
9010
9016
len ( ) : number {
@@ -9016,20 +9022,45 @@ export class NativeScripts {
9016
9022
return this . items [ index ] ;
9017
9023
}
9018
9024
9019
- add ( elem : NativeScript ) : void {
9025
+ add ( elem : NativeScript ) : boolean {
9026
+ if ( this . contains ( elem ) ) return true ;
9020
9027
this . items . push ( elem ) ;
9028
+ return false ;
9029
+ }
9030
+
9031
+ contains ( elem : NativeScript ) : boolean {
9032
+ for ( let item of this . items ) {
9033
+ if ( arrayEq ( item . to_bytes ( ) , elem . to_bytes ( ) ) ) {
9034
+ return true ;
9035
+ }
9036
+ }
9037
+ return false ;
9021
9038
}
9022
9039
9023
9040
static deserialize ( reader : CBORReader , path : string [ ] ) : NativeScripts {
9041
+ let nonEmptyTag = false ;
9042
+ if ( reader . peekType ( path ) == "tagged" ) {
9043
+ let tag = reader . readTaggedTag ( path ) ;
9044
+ if ( tag != 258 ) {
9045
+ throw new Error ( "Expected tag 258. Got " + tag ) ;
9046
+ } else {
9047
+ nonEmptyTag = true ;
9048
+ }
9049
+ }
9024
9050
const { items, definiteEncoding } = reader . readArray (
9025
9051
( reader , idx ) =>
9026
- NativeScript . deserialize ( reader , [ ...path , "Elem #" + idx ] ) ,
9052
+ NativeScript . deserialize ( reader , [ ...path , "NativeScript #" + idx ] ) ,
9027
9053
path ,
9028
9054
) ;
9029
- return new NativeScripts ( items , definiteEncoding ) ;
9055
+ let ret = new NativeScripts ( definiteEncoding , nonEmptyTag ) ;
9056
+ ret . setItems ( items ) ;
9057
+ return ret ;
9030
9058
}
9031
9059
9032
9060
serialize ( writer : CBORWriter ) : void {
9061
+ if ( this . nonEmptyTag ) {
9062
+ writer . writeTaggedTag ( 258 ) ;
9063
+ }
9033
9064
writer . writeArray (
9034
9065
this . items ,
9035
9066
( writer , x ) => x . serialize ( writer ) ,
0 commit comments