Skip to content

Commit

Permalink
Migration api endpoints (iotaledger#378)
Browse files Browse the repository at this point in the history
* add receipts and treasury endpoints

* fix receipts endpoints, remove unused log_request

* add endpoints to python binding

* update nodejs binding
  • Loading branch information
Thoralf-M authored Mar 4, 2021
1 parent 39efeed commit c5447ef
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 48 deletions.
50 changes: 41 additions & 9 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,28 @@ Gets the utxo changes by the given milestone index.

**Returns** a promise resolving to the [MilestoneUTXOChanges](#MilestoneUTXOChanges).

#### getReceipts(): Promise<Receipts[]>

Get all receipts.

**Returns** a promise resolving to the [Receipts](#Receipts).

#### getReceiptsMigratedAt(index): Promise<Receipts[]>

Get all receipts for a given milestone index

| Param | Type | Description |
| ----- | ------------------- | -------------------------- |
| index | <code>number</code> | The index of the milestone |

**Returns** a promise resolving to the [Receipts](#Receipts).

#### getTreasury(): Promise<Treasury>

Get the treasury amount.

**Returns** a promise resolving to the [Treasury](#Treasury).

#### reattach(messageId): Promise<Message>

Reattaches the message associated with the given id.
Expand Down Expand Up @@ -730,12 +752,10 @@ Gets the metadata of the given message.

- UnlockBlock

| Field | Type | Description |
| ----- | ------------------------------------------------------------------------------ | ----------------------------------------------------- |
| type | <code>'Signature' \| 'Reference'</code> | Unlock block type identifier |
| data | <code>WotsSignatureUnlockBlock \| Ed25519SignatureUnlockBlock \| number</code> | Unlock block data (signature type or reference index) |

- WotsSignatureUnlockBlock = number[] (WOTS signature)
| Field | Type | Description |
| ----- | -------------------------------------------------- | ----------------------------------------------------- |
| type | <code>'Signature' \| 'Reference'</code> | Unlock block type identifier |
| data | <code>Ed25519SignatureUnlockBlock \| number</code> | Unlock block data (signature type or reference index) |

- Ed25519SignatureUnlockBlock

Expand Down Expand Up @@ -807,9 +827,7 @@ Gets the metadata of the given message.

| Field | Type | Description |
| ----- | ------------------------------------------------------------------------------------ | ----------------------------------------------------- |
| data | <code>WotsSignatureUnlockBlockDto \| Ed25519SignatureUnlockBlockDto \| number</code> | Unlock block data (signature type or reference index) |

- WotsSignatureUnlockBlockDto = number[] (WOTS signature)
| data | <code>Ed25519SignatureUnlockBlockDto \| number</code> | Unlock block data (signature type or reference index) |

- Ed25519SignatureUnlockBlockDto

Expand Down Expand Up @@ -877,3 +895,17 @@ Gets the metadata of the given message.
| index | <code>number</code> | Milestone index |
| createdOutputs | <code>string[]</code> | OutputIds from new created outputs |
| consumedOutputs | <code>string[]</code> | OutputIds from consumed outputs |

### Receipts

| Field | Type | Description |
| --------------- | -------------------- | --------------- |
| receipt | <code>receipt</code> | Receipt |
| milestone_index | <code>number</code> | Milestone index |

### Treasury

| Field | Type | Description |
| ------------- | ------------------- | ------------ |
| milestone_id | <code>string</code> | Milestone id |
| amount | <code>number</code> | Amount |
3 changes: 3 additions & 0 deletions bindings/nodejs/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export declare class Client {
getAddressBalance(address: string): Promise<number>
getMilestone(index: number): Promise<MilestoneMetadata>
getMilestoneUTXOChanges(index: number): Promise<MilestoneUTXOChanges>
getReceipts(): Promise<Receipts[]>
getReceiptsMigratedAt(index: number): Promise<Receipts[]>
getTreasury(): Promise<Treasury>
reattach(messageId: string): Promise<MessageWrapper>
promote(messageId: string): Promise<MessageWrapper>
}
Expand Down
3 changes: 3 additions & 0 deletions bindings/nodejs/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ Client.prototype.getAddressOutputs = function (address, options) {
Client.prototype.getAddressBalance = promisify(Client.prototype.getAddressBalance)
Client.prototype.getMilestone = promisify(Client.prototype.getMilestone)
Client.prototype.getMilestoneUTXOChanges = promisify(Client.prototype.getMilestoneUTXOChanges)
Client.prototype.getReceipts = promisify(Client.prototype.getReceipts)
Client.prototype.getReceiptsMigratedAt = promisify(Client.prototype.getReceiptsMigratedAt)
Client.prototype.getTreasury = promisify(Client.prototype.getTreasury)
Client.prototype.retry = promisify(Client.prototype.retry)
Client.prototype.reattach = promisify(Client.prototype.reattach)
Client.prototype.promote = promisify(Client.prototype.promote)
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export declare interface Ed25519SignatureUnlockBlock {

export declare interface SignatureUnlockBlock {
type: 'Signature'
data: WotsSignatureUnlockBlock | Ed25519SignatureUnlockBlock
data: Ed25519SignatureUnlockBlock
}

export declare interface ReferenceUnlockBlock {
Expand Down
15 changes: 15 additions & 0 deletions bindings/nodejs/native/src/classes/client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub(crate) enum Api {
GetAddressOutputs(Bech32Address, AddressOutputsOptions),
GetMilestone(u32),
GetMilestoneUTXOChanges(u32),
GetReceipts(),
GetReceiptsMigratedAt(u32),
GetTreasury(),
Retry(MessageId),
Reattach(MessageId),
Promote(MessageId),
Expand Down Expand Up @@ -278,6 +281,18 @@ impl Task for ClientTask {
let milestone_utxo_changes = client.get_milestone_utxo_changes(*index).await?;
serde_json::to_string(&milestone_utxo_changes).unwrap()
}
Api::GetReceipts() => {
let receipts = client.get_receipts().await?;
serde_json::to_string(&receipts).unwrap()
}
Api::GetReceiptsMigratedAt(index) => {
let receipts = client.get_receipts_migrated_at(*index).await?;
serde_json::to_string(&receipts).unwrap()
}
Api::GetTreasury() => {
let treasury = client.get_treasury().await?;
serde_json::to_string(&treasury).unwrap()
}
Api::Retry(message_id) => {
let message = client.retry(message_id).await?;
serde_json::to_string(&MessageWrapper {
Expand Down
52 changes: 52 additions & 0 deletions bindings/nodejs/native/src/classes/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,58 @@ declare_types! {
Ok(cx.undefined().upcast())
}

method getReceipts(mut cx) {

let cb = cx.argument::<JsFunction>(0)?;
{
let this = cx.this();
let guard = cx.lock();
let id = &this.borrow(&guard).0;
let client_task = ClientTask {
client_id: id.clone(),
api: Api::GetReceipts(),
};
client_task.schedule(cb);
}

Ok(cx.undefined().upcast())
}

method getReceiptsMigratedAt(mut cx) {
let milestone_index = cx.argument::<JsNumber>(0)?.value() as u32;

let cb = cx.argument::<JsFunction>(1)?;
{
let this = cx.this();
let guard = cx.lock();
let id = &this.borrow(&guard).0;
let client_task = ClientTask {
client_id: id.clone(),
api: Api::GetReceiptsMigratedAt(milestone_index),
};
client_task.schedule(cb);
}

Ok(cx.undefined().upcast())
}

method getTreasury(mut cx) {

let cb = cx.argument::<JsFunction>(0)?;
{
let this = cx.this();
let guard = cx.lock();
let id = &this.borrow(&guard).0;
let client_task = ClientTask {
client_id: id.clone(),
api: Api::GetTreasury(),
};
client_task.schedule(cb);
}

Ok(cx.undefined().upcast())
}

method reattach(mut cx) {
let message_id = cx.argument::<JsString>(0)?.value();
let message_id = MessageId::from_str(message_id.as_str()).expect("invalid message id");
Expand Down
44 changes: 44 additions & 0 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@ Gets the utxo changes by the given milestone index.

**Returns** the [MilestoneUTXOChanges](#milestoneutxochanges).

#### get_receipts(): Vec<ReceiptDto>

Get all receipts.

**Returns** the [ReceiptDto](#ReceiptDto).

#### get_receipts_migrated_at(index): Vec<ReceiptDto>

Get all receipts for a given milestone index.

| Param | Type | Default | Description |
| ------- | ---------------- | ---------------------- | -------------------------- |
| [index] | <code>int</code> | <code>undefined</code> | The index of the milestone |

**Returns** the [ReceiptDto](#ReceiptDto).

#### get_treasury(): TreasuryResponse

Get the treasury amount.

**Returns** the [TreasuryResponse](#TreasuryResponse).

### High-Level APIs

#### message(seed (optional), account_index (optional), initial_address_index (optional), inputs (optional), input_range_begin (optional), input_range_end (optional), outputs (optional), dust_allowance_outputs (optional), index (optional), index_raw (optional), data (optional), data_str (optional), parents (optional)): Message
Expand Down Expand Up @@ -542,6 +564,28 @@ milestone_utxo_changes = {
}
```

#### ReceiptDto

A dict with the following key/value pairs.

```python
receiptDto = {
'receipt': Receipt,
'milestone_index': int,
}
```

#### TreasuryResponse

A dict with the following key/value pairs.

```python
treasuryResponse = {
'milestone_id': str,
'amount': int,
}
```

#### UTXOInput

A dict with the following key/value pairs.
Expand Down
24 changes: 23 additions & 1 deletion bindings/python/native/src/client/full_node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::client::{
error::Result, AddressOutputsOptions, BalanceForAddressResponse, Client, InfoResponse, Message, MilestoneDto,
MilestoneUTXOChanges, OutputResponse, PeerDto, UTXOInput,
MilestoneUTXOChanges, OutputResponse, PeerDto, ReceiptDto, TreasuryResponse, UTXOInput,
};
use iota::{
Bech32Address as RustBech32Address, ClientMiner as RustClientMiner, MessageBuilder as RustMessageBuilder,
Expand Down Expand Up @@ -127,4 +127,26 @@ impl Client {
.block_on(async { self.client.get_milestone_utxo_changes(index).await })?
.into())
}
fn get_receipts(&self) -> Result<Vec<ReceiptDto>> {
let rt = tokio::runtime::Runtime::new()?;
let receipts: Vec<ReceiptDto> = rt
.block_on(async { self.client.get_receipts().await })?
.into_iter()
.map(|r| r.into())
.collect();
Ok(receipts)
}
fn get_receipts_migrated_at(&self, index: u32) -> Result<Vec<ReceiptDto>> {
let rt = tokio::runtime::Runtime::new()?;
let receipts: Vec<ReceiptDto> = rt
.block_on(async { self.client.get_receipts_migrated_at(index).await })?
.into_iter()
.map(|r| r.into())
.collect();
Ok(receipts)
}
fn get_treasury(&self) -> Result<TreasuryResponse> {
let rt = tokio::runtime::Runtime::new()?;
Ok(rt.block_on(async { self.client.get_treasury().await })?.into())
}
}
4 changes: 2 additions & 2 deletions bindings/python/native/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use pyo3::prelude::*;
use std::{collections::HashMap, time::Duration};
use types::{
AddressBalancePair, AddressOutputsOptions, BalanceForAddressResponse, BrokerOptions, InfoResponse, Input, Message,
MessageMetadataResponse, MilestoneDto, MilestoneUTXOChanges, Output, OutputResponse, PeerDto, UTXOInput,
BECH32_HRP,
MessageMetadataResponse, MilestoneDto, MilestoneUTXOChanges, Output, OutputResponse, PeerDto, ReceiptDto,
TreasuryResponse, UTXOInput, BECH32_HRP,
};

/// Client builder
Expand Down
Loading

0 comments on commit c5447ef

Please sign in to comment.