Skip to content

Commit

Permalink
feat: update nodejs bindings (#872)
Browse files Browse the repository at this point in the history
* feat: update nodejs bindings

- Change address outputs from an array to a list (object);
- Add “id” to Message interface;
- Make “confirmed” property in Message interface non-optional;
- Add “reattachmentMessageId” to Message interface;
- Add “type: ‘Transaction’” to Transaction interface;
- Nest “Transaction.essense” into “Transaction.data”;
- Make “metadata” in UTXOInput interface non-optional;
- Change “is_spent” in UTXOInput interface to “isSpent”;
- Add “Indexation” payload to RegularEssence interface;
- Add unlock_blocks to Message interface — (TODO) Should be camelCase including public_key prop;
- Add Milestone payload interface

* feat: make unlock_blocks camelCase

* fix (nodejs): address comments

- make metadata in UtxoInput interface optional;
- make payload in RegularEssence interface optional

* chore: add to .changes/ for next release
  • Loading branch information
laumair authored Feb 18, 2022
1 parent 253d990 commit b253d37
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changes/type-definitions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nodejs-binding": patch
---

Update nodejs type definitions
106 changes: 90 additions & 16 deletions bindings/nodejs/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export declare enum MessageType {
export declare interface RegularEssence {
inputs: Input[];
outputs: Output[];
payload?: Payload[];
payload?: {
type: 'Indexation'
data: {
data: number[]
index: number[]
}
};
incoming: boolean;
internal: boolean;
value: number;
Expand All @@ -35,7 +41,7 @@ export declare interface UtxoInput {
messageId: string;
index: number;
amount: number;
is_spent: boolean;
isSpent: boolean;
address: string;
};
}
Expand All @@ -54,31 +60,96 @@ export declare interface SignatureLockedDustAllowance {
remainder: boolean;
}

export declare type Output =
| {
type: 'SignatureLockedSingleOutput';
data: SignatureLockedSingleOutput;
}
| {
type: 'SignatureLockedDustAllowance';
data: SignatureLockedDustAllowance;
};
export declare type Output = {
type: 'SignatureLockedSingleOutput';
data: SignatureLockedSingleOutput;
} | {
type: 'SignatureLockedDustAllowance';
data: SignatureLockedDustAllowance;
};

export declare interface Transaction {
essence: Essence;
type: 'Transaction';
data: {
essence: Essence;
unlockBlocks: {
type: 'Signature'
data: {
type: 'Ed25519'
data: {
public_key: number[]
signature: number[]
}
}
}[]
}
}

interface ReceiptFunds {
output: {
address: string
amount: number
remainder: boolean
}
tailTransactionHash: string
}

interface Receipt {
type: 'Receipt'
data: {
last: boolean
migratedAt: number
funds: ReceiptFunds[]
transaction: {
data: {
input: {
data: string
type: 'Treasury'
}
output: {
data: {
amount: number
}
}
}
type: 'TreasuryTransaction'
}
}
}

interface MilestoneEssence {
index: number
merkleProof: number[]
nextPowScore: number
nextPowScoreMilestoneIndex: number
parents: string[]
publicKeys: number[]
receipt: Receipt
timestamp: number
value: number
}

export interface Milestone {
type: 'Milestone'
data: {
essence: MilestoneEssence
signatures: number[]
}
}

export declare type Payload = Transaction;
export declare type Payload = Transaction | Milestone;

export declare interface Message {
id: string;
version: number;
parents: string[];
payloadLength: number;
payload: Payload;
timestamp: string;
nonce: number;
confirmed?: boolean;
confirmed: boolean;
broadcasted: boolean;
reattachmentMessageId?: string | null;
}

export declare interface AddressOutput {
Expand All @@ -95,7 +166,9 @@ export declare interface Address {
balance: number;
keyIndex: number;
internal: boolean;
outputs: AddressOutput[];
outputs: {
[outputId: string]: AddressOutput
};
}

export declare interface SyncOptions {
Expand Down Expand Up @@ -203,7 +276,7 @@ export declare class OutputKind {
static signatureLockedDustAllowance(): OutputKind;
}

export declare class SyncedAccount {}
export declare class SyncedAccount { }

export declare type NodeUrl = string;

Expand Down Expand Up @@ -279,6 +352,7 @@ export declare interface TransactionEvent {
accountId: string;
message: Message;
}

export declare class AccountManager {
constructor(options: ManagerOptions);
startBackgroundSync(
Expand Down
1 change: 1 addition & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ impl TransactionEssence {
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct MessageTransactionPayload {
essence: TransactionEssence,
#[serde(rename = "unlockBlocks")]
unlock_blocks: Box<[UnlockBlock]>,
}

Expand Down

0 comments on commit b253d37

Please sign in to comment.