Skip to content

Commit

Permalink
update type names and add dust_allowed field
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Mar 31, 2021
1 parent e62f681 commit b6b4b32
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 141 deletions.
10 changes: 9 additions & 1 deletion bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Gets the UTXO outputs associated with the given address.

**Returns** a promise resolving to a list of output ids.

#### getAddressBalance(address): Promise<number>
#### getAddressBalance(address): Promise<AddressBalance>

Gets the balance of the given address.

Expand Down Expand Up @@ -885,6 +885,14 @@ Gets the metadata of the given message.
| index | <code>string</code> | Indexation key |
| data | <code>Uint8Array</code> | Indexation data |

##### AddressBalance

| Field | Type | Description |
| ------------ | -------------------- | ---------------------- |
| address | <code>string</code> | Bech32 encoded address |
| balance | <code>number</code> | Address balance |
| dustAllowed | <code>boolean</code> | Dust allowed |

### MessageMetadata

| Field | Type | Description |
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export declare interface BrokerOptions {
export declare type Address = 'string'

export declare interface AddressBalance {
type: number
address: Address
balance: number
dust_allowed: boolean
}
8 changes: 4 additions & 4 deletions bindings/nodejs/native/src/classes/client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::MessageDto;

use crate::classes::client::dto::MessageWrapper;
use iota::{
Address, AddressOutputsOptions, ClientMiner, MessageBuilder, MessageId, Parents, Seed, TransactionId, UTXOInput,
Address, AddressOutputsOptions, ClientMiner, MessageBuilder, MessageId, Parents, Seed, TransactionId, UtxoInput,
};
use neon::prelude::*;

Expand All @@ -20,7 +20,7 @@ pub(crate) enum Api {
parents: Option<Vec<MessageId>>,
account_index: Option<usize>,
initial_address_index: Option<usize>,
inputs: Vec<UTXOInput>,
inputs: Vec<UtxoInput>,
outputs: Vec<(Address, u64)>,
dust_allowance_outputs: Vec<(Address, u64)>,
},
Expand Down Expand Up @@ -57,9 +57,9 @@ pub(crate) enum Api {
GetMessageMetadata(MessageId),
GetRawMessage(MessageId),
GetMessageChildren(MessageId),
GetOutput(UTXOInput),
GetOutput(UtxoInput),
FindOutputs {
outputs: Vec<UTXOInput>,
outputs: Vec<UtxoInput>,
addresses: Vec<String>,
},
GetAddressBalance(String),
Expand Down
8 changes: 5 additions & 3 deletions bindings/nodejs/native/src/classes/client/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

use iota::{
AddressDto, BalanceForAddressResponse as AddressBalancePair, Ed25519Signature, Essence, IndexationPayload, Input,
AddressDto, BalanceAddressResponse as AddressBalancePair, Ed25519Signature, Essence, IndexationPayload, Input,
Message, MessageId, Output, OutputDto as BeeOutput, OutputResponse as OutputMetadata, Payload, ReferenceUnlock,
RegularEssence, SignatureUnlock, TransactionPayload, UTXOInput, UnlockBlock, UnlockBlocks,
RegularEssence, SignatureUnlock, TransactionPayload, UnlockBlock, UnlockBlocks, UtxoInput,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -37,7 +37,7 @@ impl TryFrom<MessageRegularEssenceDto> for RegularEssence {
.into_vec()
.into_iter()
.map(|input| {
UTXOInput::from_str(&input)
UtxoInput::from_str(&input)
.unwrap_or_else(|_| panic!("invalid input: {}", input))
.into()
})
Expand Down Expand Up @@ -214,13 +214,15 @@ impl From<OutputMetadata> for OutputMetadataDto {
pub(super) struct AddressBalanceDto {
address: String,
balance: u64,
dustAllowed: bool,
}

impl From<AddressBalancePair> for AddressBalanceDto {
fn from(value: AddressBalancePair) -> Self {
Self {
address: value.address.to_string(),
balance: value.balance,
dustAllowed: value.dust_allowed,
}
}
}
6 changes: 3 additions & 3 deletions bindings/nodejs/native/src/classes/client/message_sender.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota::{Address, MessageId, Seed, TransactionId, UTXOInput};
use iota::{Address, MessageId, Seed, TransactionId, UtxoInput};
use neon::prelude::*;

use super::{parse_address, Api, ClientTask};
Expand All @@ -16,7 +16,7 @@ pub struct MessageSender {
seed: Option<String>,
account_index: Option<usize>,
initial_address_index: Option<usize>,
inputs: Vec<UTXOInput>,
inputs: Vec<UtxoInput>,
input_range: Range<usize>,
outputs: Vec<(Address, u64)>,
dust_allowance_outputs: Vec<(Address, u64)>,
Expand Down Expand Up @@ -174,7 +174,7 @@ declare_types! {
let mut this = cx.this();
let guard = cx.lock();
let inputs = &mut this.borrow_mut(&guard).inputs;
inputs.push(UTXOInput::new(transaction_id, index).expect("invalid UTXO input"));
inputs.push(UtxoInput::new(transaction_id, index).expect("invalid UTXO input"));
}

Ok(cx.this().upcast())
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/native/src/classes/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use iota::{
message::prelude::{Address, MessageId, TransactionId, UTXOInput},
message::prelude::{Address, MessageId, TransactionId, UtxoInput},
AddressOutputsOptions, OutputType, Seed,
};
use neon::prelude::*;
Expand Down Expand Up @@ -357,7 +357,7 @@ declare_types! {

method getOutput(mut cx) {
let output_id = cx.argument::<JsString>(0)?.value();
let output_id = UTXOInput::from_str(output_id.as_str()).expect("invalid output id");
let output_id = UtxoInput::from_str(output_id.as_str()).expect("invalid output id");
let cb = cx.argument::<JsFunction>(1)?;
{
let this = cx.this();
Expand All @@ -379,7 +379,7 @@ declare_types! {
let mut outputs = vec![];
for js_output_id in js_output_ids {
let output_id: Handle<JsString> = js_output_id.downcast_or_throw(&mut cx)?;
let output_id = UTXOInput::from_str(output_id.value().as_str()).expect("invalid output id");
let output_id = UtxoInput::from_str(output_id.value().as_str()).expect("invalid output id");
outputs.push(output_id);
}

Expand Down
13 changes: 7 additions & 6 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,17 @@ Gets the UTXO outputs associated with the given output id.

**Returns** the OutputResponse[#outputresponse].

#### get_address_balance(address): BalanceForAddressResponse
#### get_address_balance(address): BalanceAddressResponse

Gets the balance in the address.

| Param | Type | Default | Description |
| --------- | ---------------------- | ---------------------- | ------------------------- |
| [address] | <code>list[str]</code> | <code>undefined</code> | The address Bech32 string |

**Returns** the [BalanceForAddressResponse](#balanceforaddressresponse).
**Returns** the [BalanceAddressResponse](#BalanceAddressResponse).

#### get_address_outputs(address, options (optional)): list[UTXOInput]
#### get_address_outputs(address, options (optional)): list[UtxoInput]

Gets the UTXO outputs associated with the given address.

Expand All @@ -266,7 +266,7 @@ Gets the UTXO outputs associated with the given address.
| [address] | <code>str</code> | <code>undefined</code> | The address Bech32 string |
| [options] | <code>[[AddressOutputsOptions](#addressoutputsoptions)]</code> | <code>undefined</code> | The query filters |

**Returns** the list of [UTXOInput](#utxoinput).
**Returns** the list of [UtxoInput](#UtxoInput).

#### find_outputs(output_ids (optional), addresses (optional)): list[OutputResponse]

Expand Down Expand Up @@ -564,7 +564,7 @@ message_metadata_response = {

Please refer to [LedgerInclusionStateDto](#ledgerinclusionstatedto) for the details of this type.

#### BalanceForAddressResponse
#### BalanceAddressResponse

A dict with the following key/value pairs.

Expand All @@ -584,6 +584,7 @@ A dict with the following key/value pairs.
address_balance_pair = {
'address': str,
'balance': int
'dust_allowed': bool
}
```

Expand Down Expand Up @@ -633,7 +634,7 @@ treasuryResponse = {
}
```

#### UTXOInput
#### UtxoInput

A dict with the following key/value pairs.

Expand Down
18 changes: 9 additions & 9 deletions bindings/python/native/src/client/full_node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

use crate::client::{
error::Result, AddressOutputsOptions, BalanceForAddressResponse, Client, InfoResponse, Message, MilestoneDto,
MilestoneUTXOChanges, OutputResponse, PeerDto, ReceiptDto, TreasuryResponse, UTXOInput,
error::Result, AddressOutputsOptions, BalanceAddressResponse, Client, InfoResponse, Message, MilestoneDto,
MilestoneUTXOChanges, OutputResponse, PeerDto, ReceiptDto, TreasuryResponse, UtxoInput,
};
use iota::{
ClientMiner as RustClientMiner, MessageBuilder as RustMessageBuilder, MessageId as RustMessageId, Parents,
TransactionId as RustTransactionId, UTXOInput as RustUTXOInput,
TransactionId as RustTransactionId, UtxoInput as RustUtxoInput,
};
use pyo3::prelude::*;

Expand Down Expand Up @@ -53,12 +53,12 @@ impl Client {
Ok(crate::block_on(async { self.client.post_message(&msg).await })?.to_string())
}
fn get_output(&self, output_id: String) -> Result<OutputResponse> {
Ok(crate::block_on(async { self.client.get_output(&RustUTXOInput::from_str(&output_id)?).await })?.into())
Ok(crate::block_on(async { self.client.get_output(&RustUtxoInput::from_str(&output_id)?).await })?.into())
}
fn get_address_balance(&self, address: &str) -> Result<BalanceForAddressResponse> {
fn get_address_balance(&self, address: &str) -> Result<BalanceAddressResponse> {
Ok(crate::block_on(async { self.client.get_address().balance(&String::from(address)).await })?.into())
}
fn get_address_outputs(&self, address: &str, options: Option<AddressOutputsOptions>) -> Result<Vec<UTXOInput>> {
fn get_address_outputs(&self, address: &str, options: Option<AddressOutputsOptions>) -> Result<Vec<UtxoInput>> {
let outputs = crate::block_on(async {
self.client
.get_address()
Expand All @@ -68,7 +68,7 @@ impl Client {
Ok((*outputs)
.to_vec()
.iter()
.map(|output| UTXOInput {
.map(|output| UtxoInput {
transaction_id: output.output_id().transaction_id().as_ref().to_vec(),
index: output.output_id().index(),
})
Expand All @@ -79,10 +79,10 @@ impl Client {
output_ids: Option<Vec<String>>,
addresses: Option<Vec<String>>,
) -> Result<Vec<OutputResponse>> {
let output_ids: Vec<RustUTXOInput> = output_ids
let output_ids: Vec<RustUtxoInput> = output_ids
.unwrap_or_default()
.iter()
.map(|input| RustUTXOInput::from_str(input).unwrap_or_else(|_| panic!("invalid input: {}", input)))
.map(|input| RustUtxoInput::from_str(input).unwrap_or_else(|_| panic!("invalid input: {}", input)))
.collect();
let addresses: Vec<String> = addresses
.unwrap_or_default()
Expand Down
5 changes: 3 additions & 2 deletions bindings/python/native/src/client/high_level_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::client::{
AddressBalancePair, Client, Input, Message, MessageMetadataResponse, Output,
};
use iota::{
MessageId as RustMessageId, Seed as RustSeed, TransactionId as RustTransactionId, UTXOInput as RustUTXOInput,
MessageId as RustMessageId, Seed as RustSeed, TransactionId as RustTransactionId, UtxoInput as RustUtxoInput,
};
use pyo3::{exceptions, prelude::*};
use std::{
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Client {
}
if let Some(inputs) = inputs {
for input in inputs {
send_builder = send_builder.with_input(RustUTXOInput::new(
send_builder = send_builder.with_input(RustUtxoInput::new(
RustTransactionId::from_str(&input.transaction_id[..])?,
input.index,
)?);
Expand Down Expand Up @@ -286,6 +286,7 @@ impl Client {
.map(|address_balance| AddressBalancePair {
address: address_balance.address.clone(),
balance: address_balance.balance,
dust_allowed: address_balance.dust_allowed,
})
.collect())
}
Expand Down
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 @@ -10,9 +10,9 @@ use iota::{Api, BrokerOptions as RustBrokerOptions, Client as RustClient};
use pyo3::prelude::*;
use std::{collections::HashMap, time::Duration};
use types::{
AddressBalancePair, AddressOutputsOptions, BalanceForAddressResponse, BrokerOptions, InfoResponse, Input, Message,
AddressBalancePair, AddressOutputsOptions, BalanceAddressResponse, BrokerOptions, InfoResponse, Input, Message,
MessageMetadataResponse, MilestoneDto, MilestoneUTXOChanges, Output, OutputResponse, PeerDto, ReceiptDto,
TreasuryResponse, UTXOInput, BECH32_HRP,
TreasuryResponse, UtxoInput, BECH32_HRP,
};

/// Client builder
Expand Down
Loading

0 comments on commit b6b4b32

Please sign in to comment.