Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/example_bls_multisig.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pactus.crypto.bls.private_key import PrivateKey
from pactus.crypto.bls.public_key import PublicKey
from pactus.crypto.bls.signature import Signature
from pactus.crypto.bls import PrivateKey
from pactus.crypto.bls import PublicKey
from pactus.crypto.bls import Signature


def main() -> None:
Expand Down
10 changes: 3 additions & 7 deletions examples/example_key_generation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import argparse

from pactus.crypto.hrp import HRP
from pactus.crypto.address import AddressType
from pactus.crypto.bls.private_key import PrivateKey as BLSPrivateKey
from pactus.crypto.ed25519.private_key import PrivateKey as Ed25519PrivateKey
from pactus.crypto.private_key import PrivateKey
from pactus.crypto.public_key import PublicKey
from pactus.crypto.address import Address
from pactus.crypto import Address, AddressType, HRP, PrivateKey, PublicKey
from pactus.crypto.bls import PrivateKey as BLSPrivateKey
from pactus.crypto.ed25519 import PrivateKey as Ed25519PrivateKey


def main() -> None:
Expand Down
10 changes: 5 additions & 5 deletions examples/example_transfer_transaction_bls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pactus.crypto.hrp import HRP
from pactus.crypto.address import Address
from pactus.crypto.bls.private_key import PrivateKey
from pactus.transaction.transaction import Transaction
from pactus.amount import Amount
from pactus.crypto import HRP
from pactus.crypto import Address
from pactus.crypto.bls import PrivateKey
from pactus.transaction import Transaction
from pactus.types.amount import Amount


def main() -> None:
Expand Down
10 changes: 5 additions & 5 deletions examples/example_transfer_transaction_ed25519.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pactus.crypto.hrp import HRP
from pactus.crypto.address import Address
from pactus.crypto.ed25519.private_key import PrivateKey
from pactus.transaction.transaction import Transaction
from pactus.amount import Amount
from pactus.crypto import HRP
from pactus.crypto import Address
from pactus.crypto.ed25519 import PrivateKey
from pactus.transaction import Transaction
from pactus.types.amount import Amount


def main() -> None:
Expand Down
6 changes: 6 additions & 0 deletions pactus/crypto/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .address import Address, AddressType
from .hrp import HRP
from .private_key import PrivateKey
from .public_key import PublicKey

__all__ = ["HRP", "Address", "AddressType", "PrivateKey", "PublicKey"]
6 changes: 6 additions & 0 deletions pactus/crypto/bls/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .private_key import PrivateKey
from .public_key import PublicKey
from .signature import DST, SIGNATURE_TYPE_BLS, Signature

__all__ = ["DST", "SIGNATURE_TYPE_BLS", "PrivateKey", "PublicKey", "Signature"]

6 changes: 6 additions & 0 deletions pactus/crypto/ed25519/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .private_key import PrivateKey
from .public_key import PublicKey
from .signature import SIGNATURE_TYPE_ED25519, Signature

__all__ = ["SIGNATURE_TYPE_ED25519", "PrivateKey", "PublicKey", "Signature"]

6 changes: 6 additions & 0 deletions pactus/crypto/hrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class HRP:
PUBLIC_KEY_HRP = "public"
PRIVATE_KEY_HRP = "secret"

@classmethod
def use_mainnet(cls) -> None:
cls.ADDRESS_HRP = "pc"
cls.PUBLIC_KEY_HRP = "public"
cls.PRIVATE_KEY_HRP = "secret"

@classmethod
def use_testnet(cls) -> None:
cls.ADDRESS_HRP = "tpc"
Expand Down
3 changes: 3 additions & 0 deletions pactus/transaction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .transaction import Transaction

__all__ = ["Transaction"]
2 changes: 1 addition & 1 deletion pactus/transaction/_payload.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC, abstractmethod
from enum import Enum

from pactus.amount import Amount
from pactus.crypto.address import Address
from pactus.encoding import encoding
from pactus.types.amount import Amount


class PayloadType(Enum):
Expand Down
2 changes: 1 addition & 1 deletion pactus/transaction/transaction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pactus.amount import Amount
from pactus.crypto.address import Address
from pactus.crypto.private_key import PrivateKey
from pactus.crypto.public_key import PublicKey
from pactus.crypto.signature import Signature
from pactus.encoding import encoding
from pactus.types.amount import Amount

from ._payload import (
BondPayload,
Expand Down
3 changes: 3 additions & 0 deletions pactus/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .amount import Amount

__all__ = ["Amount"]
6 changes: 6 additions & 0 deletions pactus/amount.py → pactus/types/amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def __eq__(self, other: "Amount") -> bool:
def __hash__(self) -> int:
return hash(self.value)

def __str__(self) -> str:
"""Return a string representation of the amount in PAC."""
pac_value = self.value / NANO_PAC_PER_PAC
return f"{pac_value}"

@classmethod
def from_nano_pac(cls, a: int) -> "Amount":
"""Store the value as NanoPAC in the Amount instance."""
Expand Down Expand Up @@ -76,3 +81,4 @@ def round(self: float) -> float:
return self - 0.5

return self + 0.5

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="pactus-sdk",
version="1.2.4",
version="1.3.0",
author="Pactus Development Team",
author_email="info@pactus.org",
description="Pactus Development Kit",
Expand Down
46 changes: 45 additions & 1 deletion tests/test_amount.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from pactus.amount import NANO_PAC_PER_PAC, Amount
from pactus.types.amount import NANO_PAC_PER_PAC, Amount


class TestAmount(unittest.TestCase):
Expand Down Expand Up @@ -61,6 +61,50 @@ def test_from_string(self):
amt = Amount.from_string(case["input"])
self.assertEqual(amt, case["expected"])

def test_str(self):
test_cases = [
{
"input": Amount(0),
"expected": "0.0",
},
{
"input": Amount.from_pac(42.5),
"expected": "42.5",
},
{
"input": Amount.from_pac(1.0),
"expected": "1.0",
},
{
"input": Amount.from_pac(0.5),
"expected": "0.5",
},
{
"input": Amount.from_pac(1000000.0),
"expected": "1000000.0",
},
{
"input": Amount.from_pac(0.000000001),
"expected": "1e-09",
},
{
"input": Amount.from_pac(-10.5),
"expected": "-10.5",
},
{
"input": Amount.from_nano_pac(1000000000),
"expected": "1.0",
},
{
"input": Amount.from_nano_pac(500000000),
"expected": "0.5",
},
]

for case in test_cases:
result = str(case["input"])
self.assertEqual(result, case["expected"])


if __name__ == "__main__":
unittest.main()
6 changes: 3 additions & 3 deletions tests/test_crypto_bls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest

from pactus.crypto.bls.private_key import PrivateKey as BLSPrivateKey
from pactus.crypto.bls.public_key import PublicKey as BLSPublicKey
from pactus.crypto.bls.signature import Signature as BLSSignature
from pactus.crypto.bls import PrivateKey as BLSPrivateKey
from pactus.crypto.bls import PublicKey as BLSPublicKey
from pactus.crypto.bls import Signature as BLSSignature


class TestBLSCrypto(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_crypto_ed25519.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest

from pactus.crypto.ed25519.private_key import PrivateKey as Ed25519PrivateKey
from pactus.crypto.ed25519.public_key import PublicKey as Ed25519PublicKey
from pactus.crypto.ed25519.signature import Signature as Ed25519Signature
from pactus.crypto.ed25519 import PrivateKey as Ed25519PrivateKey
from pactus.crypto.ed25519 import PublicKey as Ed25519PublicKey
from pactus.crypto.ed25519 import Signature as Ed25519Signature


class TestEd25519Crypto(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest

from pactus.crypto.address import Address
from pactus.crypto.bls.private_key import PrivateKey
from pactus.transaction.transaction import Transaction
from pactus.amount import Amount
from pactus.crypto.bls import PrivateKey
from pactus.transaction import Transaction
from pactus.types.amount import Amount


class TestTransaction(unittest.TestCase):
Expand Down
Loading