-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vscode | ||
|
||
*.pyc |
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,34 @@ | ||
# ash.avalanche filters | ||
|
||
The collection provides the following filters: | ||
|
||
- `ash.avalanche.convert`: convert an amount between AVAX units | ||
|
||
## ash.avalanche.convert | ||
|
||
### Usage | ||
|
||
This filter is useful to submit transactions without errors in the number of zeros: | ||
|
||
```yaml | ||
ash.avalanche.tx: | ||
http_host: "{{ avalanchego_http_host }}" | ||
blockchain: X | ||
method: avm.send | ||
username: "{{ avax_transfer_from_username }}" | ||
password: "{{ avax_transfer_from_password }}" | ||
params: | ||
to: "{{ avax_transfer_to_address_bech32 }}" | ||
assetID: AVAX | ||
amount: "{{ 25 | ash.avalanche.convert('AVAX', 'nAVAX') | int }}" | ||
``` | ||
### Supported units | ||
| Unit | Amount in wei | | ||
| ----------------- | ------------------------------ | | ||
| `wei` | `1` | | ||
| `gwei` or `navax` | `1e9` (`1000000000`) | | ||
| `avax` or `eth` | `1e18` (`1000000000000000000`) | | ||
|
||
**Note:** The filter is not case sensitive: `ash.avalanche.convert('AVAX', 'nAVAX')` is the same as `ash.avalanche.convert('avax', 'navax')` |
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,29 @@ | ||
#!/usr/bin/python | ||
# Copyright 2022 TOSIT.IO | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from ansible.errors import AnsibleError | ||
|
||
|
||
class FilterModule(object): | ||
def filters(self): | ||
return {'convert': self.convert} | ||
|
||
def convert(self, amount, from_unit, to_unit): | ||
units = { | ||
'wei': 1, | ||
'gwei': 1e9, | ||
'navax': 1e9, | ||
'avax': 1e18, | ||
'eth': 1e18, | ||
} | ||
|
||
from_unit_lower = from_unit.lower() | ||
to_unit_lower = to_unit.lower() | ||
|
||
if from_unit_lower not in units.keys() or to_unit_lower not in units.keys(): | ||
raise AnsibleError( | ||
f'Unknown unit. Available units: {", ".join(units.keys())}' | ||
) | ||
|
||
return amount * units[from_unit_lower] / units[to_unit_lower] |
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