Skip to content

Commit

Permalink
feat: remove threshold parameter from getBalances()
Browse files Browse the repository at this point in the history
IRI removes support for threshold parameter in version [1.8.6](iotaledger/iri#1768).

This PR removes the usage of threshold parameter from the lib.

Related: iotaledger/iri#1851
  • Loading branch information
laumair committed Jun 8, 2020
1 parent 5e2501c commit bd06a21
Show file tree
Hide file tree
Showing 26 changed files with 1,933 additions and 1,287 deletions.
6 changes: 3 additions & 3 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function createAccountWithPreset<X, Y, Z>(preset: AccountPreset<X, Y, Z>)
getTotalBalance: () => {
return persistence
.ready()
.then(() => network.getBalances(addresses, 100))
.then(() => network.getBalances(addresses))
.then(({ balances }) => balances.reduce((acc: number, b: number) => (acc += b), 0))
},
getAvailableBalance: () => {
Expand All @@ -257,7 +257,7 @@ export function createAccountWithPreset<X, Y, Z>(preset: AccountPreset<X, Y, Z>)
.then(currentTime => {
const depositsListCopy = [...depositsList]
return network
.getBalances(depositsListCopy.map(({ address }) => tritsToTrytes(address)), 100)
.getBalances(depositsListCopy.map(({ address }) => tritsToTrytes(address)))
.then(({ balances }: { balances: ReadonlyArray<number> }) => {
let acc = 0
depositsListCopy.forEach((input, i) => {
Expand Down Expand Up @@ -287,7 +287,7 @@ export function createAccountWithPreset<X, Y, Z>(preset: AccountPreset<X, Y, Z>)
)
.then(depositsListCopy =>
network
.getBalances(depositsListCopy.map(deposit => deposit.address), 100)
.getBalances(depositsListCopy.map(deposit => deposit.address))
.then(({ balances }: { balances: ReadonlyArray<number> }) =>
depositsListCopy.map((deposit, i) => ({
...deposit,
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function networkAdapter({ provider }: NetworkParams): Network {

return {
getTrytes: hashes => (hashes.length > 0 ? getTrytes(hashes) : Promise.resolve([])),
getBalance: (address): Promise<number> => getBalances([address], 100).then(({ balances }) => balances[0]),
getBalance: (address): Promise<number> => getBalances([address]).then(({ balances }) => balances[0]),
getBalances,
getConsistency: createCheckConsistency(httpClient),
getLatestInclusion: hashes => (hashes.length > 0 ? getLatestInclusion(hashes) : Promise.resolve([])),
Expand Down
1 change: 0 additions & 1 deletion packages/account/test/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const assertBalance = (address: Trytes, balance: number) =>
.post('/', {
command: IRICommand.GET_BALANCES,
addresses: [noChecksum(address)],
threshold: 100,
})
.times(1)
.reply(200, {
Expand Down
54 changes: 39 additions & 15 deletions packages/bundle-validator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,53 @@ yarn add @iota/bundle-validator

* [bundle-validator](#module_bundle-validator)

* [~validateSignatures(bundle)](#module_bundle-validator..validateSignatures)
* [.validateBundleSignatures(bundle)](#module_bundle-validator.validateBundleSignatures)

* [~isBundle(bundle)](#module_bundle-validator..isBundle)
* [.isBundle(bundle)](#module_bundle-validator.isBundle)


<a name="module_bundle-validator..validateSignatures"></a>
<a name="module_bundle-validator.validateBundleSignatures"></a>

### *bundle-validator*~validateSignatures(bundle)
### *bundle-validator*.validateBundleSignatures(bundle)
**Summary**: Validates the signatures in a given bundle

| Param | Type |
| --- | --- |
| bundle | <code>Array.&lt;Transaction&gt;</code> |
| Param | Type | Description |
| --- | --- | --- |
| bundle | <code>Array.&lt;Transaction&gt;</code> | Transaction trytes |

Validates all signatures of a bundle.
This method takes an array of transaction trytes and checks if the signatures are valid.

<a name="module_bundle-validator..isBundle"></a>
## Related methods

### *bundle-validator*~isBundle(bundle)
To get a bundle's transaction trytes from the Tangle, use the [`getBundle()`](#module_core.getBundle) method.

| Param | Type |
| --- | --- |
| bundle | <code>Array.&lt;Transaction&gt;</code> |
**Returns**: <code>boolean</code> - Whether the signatures are valid
**Example**
```js
let valid = Validator.validateBundleSignatures(bundle);
```
<a name="module_bundle-validator.isBundle"></a>

### *bundle-validator*.isBundle(bundle)
**Summary**: Validates the structure and contents of a given bundle.

| Param | Type | Description |
| --- | --- | --- |
| bundle | <code>Array.&lt;Transaction&gt;</code> | Transaction trytes |

This method takes an array of transaction trytes and validates whether they form a valid bundle by checking the following:

Checks if a bundle is _syntactically_ valid.
Validates signatures and overall structure.
- Addresses in value transactions have a 0 trit at the end, which means they were generated using the Kerl hashing function
- Transactions in the bundle array are in the same order as their `currentIndex` field
- The total value of all transactions in the bundle sums to 0
- The bundle hash is valid

## Related methods

To get a bundle's transaction trytes from the Tangle, use the [`getBundle()`](#module_core.getBundle) method.

**Returns**: <code>boolean</code> - bundle - Whether the bundle is valid
**Example**
```js
let bundle = Validator.isBundle(bundle);
```
132 changes: 86 additions & 46 deletions packages/bundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,79 +21,119 @@ yarn add @iota/bundle

* [bundle](#module_bundle)

* [~createBundle([entries])](#module_bundle..createBundle)
* _static_
* [.addEntry(entry, bundle)](#module_bundle.addEntry)

* [~addEntry(entry, bundle)](#module_bundle..addEntry)
* [.finalizeBundle(bundle)](#module_bundle.finalizeBundle)

* [~finalizeBundle(bundle)](#module_bundle..finalizeBundle)
* [.addSignatureOrMessage(bundle, signatureOrMessage, index)](#module_bundle.addSignatureOrMessage)

* [~addSignatureOrMessage(bundle, signatureOrMessage, index)](#module_bundle..addSignatureOrMessage)
* _inner_
* [~createBundle([entries])](#module_bundle..createBundle)

* [~valueSum(bundle, offset, length)](#module_bundle..valueSum)

<a name="module_bundle.addEntry"></a>

<a name="module_bundle..createBundle"></a>
### *bundle*.addEntry(entry, bundle)
**Summary**: Adds the given transaction entry to a bundle array.
**Throws**:

### *bundle*~createBundle([entries])
- <code>errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH</code> : Make sure that the `bundle` argument contains valid transaction trits
- <code>errors.ILLEGAL\_SIGNATURE\_OR\_MESSAGE\_LENGTH</code> : Make sure that the `entry.signatureOrMessage` argument contains 6,561 trits
- <code>errors.ILLEGAL\_ADDRESS\_LENGTH</code> : Make sure that the `entry.address` argument contains 243 trits
- <code>errors.ILLEGAL\_VALUE\_LENGTH</code> : Make sure that the `entry.value` argument contains 6,561 trits
- <code>errors.ILLEGAL\_ISSUANCE\_TIMESTAMP\_LENGTH</code> : Make sure that the `entry.timestamp` argument contains 81 trits

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [entries] | <code>Array.&lt;BundleEntry&gt;</code> | <code>[]</code> | Entries of single or multiple transactions with the same address |

Creates a bundle with given transaction entries.
| Param | Type | Description |
| --- | --- | --- |
| entry | <code>object</code> | Transaction entry object |
| entry.address | <code>Int8Array</code> | An address in trits |
| entry.value | <code>Int8Array</code> | An amount of IOTA tokens in trits |
| [entry.signatureOrMessage] | <code>Int8Array</code> | Signature fragments or a message in trits |
| [entry.issuanceTimestamp] | <code>Int8Array</code> | Unix epoch in trits |
| [entry.tag] | <code>Int8Array</code> | (deprecated) |
| bundle | <code>Int8Array</code> | Bundle array to which to add the entry object |

Adds transaction trits in the given entry object to a given bundle array.

## Related methods

See the [converter](https://github.com/iotaledger/iota.js/tree/next/packages/converter) package for methods that convert values to trits.

**Returns**: <code>Int8Array</code> - A copy of the original bundle that also includes the added entries.
**Example**
```js
let bundle = new Int8Array();

bundle = Bundle.addEntry(bundle, {
address: Converter.trytesToTrits(outputAddress),
value: Converter.valueToTrits(value),
issuanceTimestamp: Converter.valueToTrits(Math.floor(Date.now() / 1000));
});
```
<a name="module_bundle.finalizeBundle"></a>

### *bundle*.finalizeBundle(bundle)
**Summary**: Generates a bundle hash.
**Throws**:

**Returns**: <code>Array.&lt;Int8Array&gt;</code> - List of transactions in the bundle
<a name="module_bundle..addEntry"></a>
- <code>errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH</code> : Make sure that the `bundle` argument contains valid transaction trits

### *bundle*~addEntry(entry, bundle)

| Param | Type | Description |
| --- | --- | --- |
| entry | <code>object</code> | Entry of a single or multiple transactions with the same address. |
| entry.address | <code>Int8Array</code> | Address. |
| entry.value | <code>Int8Array</code> | Value to transfer in iotas. |
| [entry.signatureOrMessage] | <code>Int8Array</code> | Signature or message fragment(s). |
| [entry.timestamp] | <code>Int8Array</code> | Issuance timestamp (in seconds). |
| [entry.tag] | <code>Int8Array</code> | Optional Tag, **Deprecated**. |
| bundle | <code>Int8Array</code> | Bundle buffer. |
| bundle | <code>Int8Array</code> | Transaction trits |

Adds given transaction entry to a bundle.
This method takes an array of transaction trits, generates the bundle hash, and adds it to each transaction.

**Returns**: <code>Int8Array</code> - Bundle copy with new entries.
<a name="module_bundle..finalizeBundle"></a>
## Related methods

### *bundle*~finalizeBundle(bundle)
See the [`addEntry()`](#module_bundle.addEntry) method for creating new bundles.

| Param | Type | Description |
| --- | --- | --- |
| bundle | <code>Int8Array</code> | Bundle transaction trits |
**Returns**: <code>Int8Array</code> - Transaction trits that include a bundle hash
**Example**
```js
const result = Bundle.finalizeBundle(bundle);
```
<a name="module_bundle.addSignatureOrMessage"></a>

Finalizes a bundle by calculating the bundle hash.
### *bundle*.addSignatureOrMessage(bundle, signatureOrMessage, index)
**Summary**: Adds signature message fragments to transactions in a bundle.
**Throws**:

**Returns**: <code>Int8Array</code> - List of transactions in the finalized bundle
<a name="module_bundle..addSignatureOrMessage"></a>
- <code>errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH</code> : Make sure that the `bundle` argument contains valid transaction trits
- <code>errors.ILLEGAL\_TRANSACTION\_INDEX</code> : Make sure that the `index` argument is a number and that the bundle contains enough transactions
- <code>errors.ILLEGAL\_SIGNATURE\_OR\_MESSAGE\_LENGTH</code> : Make sure that the `signatureOrMessage` argument contains at least 6,561 trits

### *bundle*~addSignatureOrMessage(bundle, signatureOrMessage, index)

| Param | Type | Description |
| --- | --- | --- |
| bundle | <code>Int8Array</code> | Bundle buffer. |
| signatureOrMessage | <code>Int8Array</code> | Signature or message to add. |
| index | <code>number</code> | Transaction index as entry point for signature or message fragments. |
| bundle | <code>Int8Array</code> | Transaction trits |
| signatureOrMessage | <code>Int8Array</code> | Signature or message to add to the bundle |
| index | <code>number</code> | Transaction index at which to start adding the signature or message |

Adds signature message fragments to transactions in a bundle starting at offset.
This method takes an array of transaction trits, and add the given message or signature to the transactions, starting from the given index.

**Returns**: <code>Int8Array</code> - List of transactions in the updated bundle
<a name="module_bundle..valueSum"></a>
If the signature or message is too long to fit in a single transaction, it is split across the next transaction in the bundle, starting from the given index.

### *bundle*~valueSum(bundle, offset, length)
## Related methods

| Param | Type | Description |
| --- | --- | --- |
| bundle | <code>Int8Array</code> | Bundle buffer. |
| offset | <code>number</code> | Offset from the start of the bundle buffer. |
| length | <code>number</code> | Length of transactions in which values should be summed. |
See the [`addEntry()`](#module_bundle.addEntry) method for creating new bundles.

**Returns**: <code>Int8Array</code> - Transaction trits that include a bundle hash.
**Example**
```js
const signature = Converter.trytesToTrits('SIGNATURE...')
bundle.set(Bundle.addSignatureOrMessage(bundle, signature, 1));
```
<a name="module_bundle..createBundle"></a>

Sums up transaction values in a bundle starting at offset.
### *bundle*~createBundle([entries])
**Summary**: Creates a bundle array from the given transaction entries.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [entries] | <code>Array.&lt;BundleEntry&gt;</code> | <code>[]</code> | Entries of single or multiple transactions with the same address |

**Returns**: <code>number</code> - Total value of 'length' transactions in the bundle starting at offset.
**Returns**: <code>Array.&lt;Int8Array&gt;</code> - List of transactions in the bundle
82 changes: 64 additions & 18 deletions packages/checksum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,83 @@ yarn add @iota/checksum

## API Reference

<a name="module_checksum..addChecksum"></a>
<a name="module_checksum.addChecksum"></a>

### *checksum*.addChecksum(input, [checksumLength], [isAddress])
**Summary**: Generates a checksum and appends it to the given trytes.
**Throws**:

- <code>errors.INVALID\_ADDRESS</code> : Make sure that the given address is 90 trytes long.
- <code>errors.INVALID\_TRYTES</code> : Make sure that the `input` argument contains only [trytes](https://docs.iota.org/docs/getting-started/0.1/introduction/ternary)
- <code>errors.INVALID\_CHECKSUM\_LENGTH</code> : Make sure that the `checksumLength` argument is a number greater than or equal to 3. If the `isAddress` argument is set to true, make sure that the `checksumLength` argument is 9.

### *checksum*~addChecksum(input, [checksumLength], [isAddress])

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| input | <code>string</code> | | Input trytes |
| [checksumLength] | <code>number</code> | <code>9</code> | Checksum trytes length |
| [isAddress] | <code>boolean</code> | <code>true</code> | Flag to denote if given input is address. Defaults to `true`. |
| input | <code>string</code> | | 81 trytes to which to append the checksum |
| [checksumLength] | <code>number</code> | <code>9</code> | Length of the checksum to generate |
| [isAddress] | <code>boolean</code> | <code>true</code> | Whether the input is an address |

This method takes 81 trytes, which could be an address or a seed, generates the [checksum](https://docs.iota.org/docs/getting-started/0.1/clients/checksums) and appends it to the trytes.

Generates and appends the 9-tryte checksum of the given trytes, usually an address.
To generate a checksum that is less than 9 trytes long, make sure to set the `isAddress` argument to false.

**Returns**: <code>string</code> - Address (with checksum)
<a name="module_checksum..removeChecksum"></a>
## Related methods

To generate an address, use the [`getNewAddress()`](#module_core.getNewAddress) method.

**Returns**: <code>string</code> - The original trytes with an appended checksum.
**Example**
```js
let addressWithChecksum = Checksum.addChecksum('ADDRESS...');
```
<a name="module_checksum.removeChecksum"></a>

### *checksum*.removeChecksum(input)
**Summary**: Removes the checksum from the given address.
**Throws**:

- <code>errors.INVALID\_ADDRESS</code> : Make sure that the given address is 90 trytes long.

### *checksum*~removeChecksum(input)

| Param | Type | Description |
| --- | --- | --- |
| input | <code>string</code> | Input trytes |
| input | <code>string</code> | Address from which to remove the checksum |

This method takes an address of 90 trytes, and removes the last 9 trytes to return the address without a checksum.

Removes the 9-trytes checksum of the given input.
## Related methods

**Returns**: <code>string</code> - Trytes without checksum
<a name="module_checksum..isValidChecksum"></a>
To generate an address, use the [`getNewAddress()`](#module_core.getNewAddress) method.
To add a checksum to an address, use the [`addChecksum()`](#module_checksum.addChecksum) method.

### *checksum*~isValidChecksum(addressWithChecksum)
**Returns**: <code>string</code> - The original address without the appended checksum.
**Example**
```js
let addressWithoutChecksum = Checksum.removeChecksum('ADDRESS...');
```
<a name="module_checksum.isValidChecksum"></a>

### *checksum*.isValidChecksum(addressWithChecksum)
**Summary**: Validates the checksum of an address.
**Throws**:

- <code>errors.INVALID\_ADDRESS</code> : Make sure that the given address is 90 trytes long.

| Param | Type |
| --- | --- |
| addressWithChecksum | <code>string</code> |

Validates the checksum of the given address trytes.
| Param | Type | Description |
| --- | --- | --- |
| addressWithChecksum | <code>string</code> | Address with a checksum |

This method takes an address of 90 trytes, and checks if the checksum is valid.

## Related methods

To generate an address, use the [`getNewAddress()`](#module_core.getNewAddress) method.
To add a checksum to an address, use the [`addChecksum()`](#module_checksum.addChecksum) method.

**Returns**: <code>boolean</code> - Whether the checksum is valid.
**Example**
```js
let valid = Checksum.isValidChecksum('ADDRESS...');
```
Loading

0 comments on commit bd06a21

Please sign in to comment.