-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from MickWang/new_ontid
ontid 2.0 api update
- Loading branch information
Showing
9 changed files
with
1,963 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as Long from 'long'; | ||
import { writeVarBytes } from '../../../transaction/scriptBuilder'; | ||
import { bigIntToBytes, str2hexstr } from '../../../utils'; | ||
|
||
type GroupType = string | Group; | ||
|
||
export default class Group { | ||
members: GroupType[]; | ||
/** | ||
* | ||
* Define the threshold number of signatures | ||
* @type {number} | ||
* @memberof Group | ||
*/ | ||
threshold: number; | ||
|
||
public constructor(members: GroupType[], threshold: number) { | ||
this.members = members; | ||
this.threshold = threshold; | ||
} | ||
|
||
public serialize(): string { | ||
let result = ''; | ||
const length = Long.fromNumber(this.members.length); | ||
result += writeVarBytes(bigIntToBytes(length)); | ||
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(Long.fromNumber(this.threshold)); | ||
result += writeVarBytes(th); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as Long from 'long'; | ||
import { writeVarBytes } from '../../../transaction/scriptBuilder'; | ||
import { bigIntToBytes, str2hexstr } from '../../../utils'; | ||
|
||
export class Signer { | ||
id: string; | ||
index: number; | ||
|
||
public constructor(id: string, index: number) { | ||
this.id = id; | ||
this.index = index; | ||
} | ||
|
||
public serialize(): string { | ||
let result = ''; | ||
result += writeVarBytes(str2hexstr(this.id)); | ||
const bi = bigIntToBytes(Long.fromNumber(this.index)); | ||
result += writeVarBytes(bi); | ||
return result; | ||
} | ||
} | ||
|
||
export function serializeSigners(signers: Signer[]): string { | ||
let result = ''; | ||
const length = bigIntToBytes(Long.fromNumber(signers.length)); | ||
result += writeVarBytes(length); | ||
for (const s of signers) { | ||
result += s.serialize(); | ||
} | ||
return result; | ||
} |
Oops, something went wrong.