import * as Long from 'long' ; import { writeVarBytes } from '../../../transaction/scriptBuilder' ; import { bigIntToBytes , str2hexstr } from '../../../utils' ; export type GroupType = string | Group ; export default class Group { members : GroupType [ ] ; type { number } memberof threshold : number ; public constructor ( members , threshold ) { this . members = members ; this . threshold = threshold ; } public serialize ( ) { let result = '' ; const length = Long . fromNumber ( this . members . length ) ; result += writeVarBytes ( bigIntToBytes ( length . toNumber ( ) ) ) ; for ( const obj of this . members ) { if ( typeof obj === 'string' ) { result += writeVarBytes ( str2hexstr ( obj ) ) ; } else if ( obj instanceof Group ) { result += writeVarBytes ( obj . serialize ( ) ) ; } } const th = bigIntToBytes ( this . threshold ) ; result += writeVarBytes ( th ) ; return result ; } }