Skip to content

Commit

Permalink
Improve: HTLC smart contract current working directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
meherett committed Nov 20, 2021
1 parent aa5e1b7 commit 0ca8966
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions swap/providers/bitcoin/htlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Script, ScriptBuilder, P2shScript, IfElseScript
)
from btcpy.structs.transaction import Locktime
from pathlib import PurePosixPath
from datetime import datetime
from typing import (
Optional, Union
)

import hashlib
import sys
import os

from ...exceptions import (
Expand Down Expand Up @@ -84,7 +84,7 @@ def build_htlc(self, secret_hash: str, recipient_address: str, sender_address: s
raise AddressError(f"Invalid Bitcoin sender '{sender_address}' {self._network} address.")

# Get current working directory path (like linux or unix path).
cwd: str = PurePosixPath(os.path.dirname(os.path.realpath(__file__))).__str__().replace("\\", "/")
cwd: str = os.path.dirname(sys.modules[__package__].__file__)

with open(f"{cwd}/contracts/htlc.script", "r", encoding="utf-8") as htlc_script:
htlc_opcode: str = htlc_script.readlines()[-1] # HTLC OP_Code script
Expand Down
4 changes: 2 additions & 2 deletions swap/providers/bytom/htlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from pybytom.script.opcode import (
OP_FALSE, OP_DEPTH, OP_CHECKPREDICATE
)
from pathlib import PurePosixPath
from equity import Equity
from ctypes import c_int64
from typing import (
Optional, List, Union
)

import sys
import os

from ...exceptions import (
Expand Down Expand Up @@ -92,7 +92,7 @@ def build_htlc(self, secret_hash: str, recipient_public_key: str, sender_public_
if use_script:

# Get current working directory path (like linux or unix path).
cwd: str = PurePosixPath(os.path.dirname(os.path.realpath(__file__))).__str__().replace("\\", "/")
cwd: str = os.path.dirname(sys.modules[__package__].__file__)

with open(f"{cwd}/contracts/htlc.equity", "r", encoding="utf-8") as htlc_equity_file:
htlc_script: str = "".join(htlc_equity_file.readlines()[-14:])
Expand Down
4 changes: 2 additions & 2 deletions swap/providers/ethereum/htlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from typing import (
Optional, Type, Union
)
from pathlib import PurePosixPath
from web3.types import (
Wei, ChecksumAddress
)

import json
import sys
import os

from ...exceptions import (
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self, contract_address: Optional[str] = None, network: str = config
)

# Get current working directory path (like linux or unix path).
cwd: str = PurePosixPath(os.path.dirname(os.path.realpath(__file__))).__str__().replace("\\", "/")
cwd: str = os.path.dirname(sys.modules[__package__].__file__)

if use_script:
solcx = __import__("solcx")
Expand Down
4 changes: 2 additions & 2 deletions swap/providers/vapor/htlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from pybytom.script.opcode import (
OP_FALSE, OP_DEPTH, OP_CHECKPREDICATE
)
from pathlib import PurePosixPath
from equity import Equity
from ctypes import c_int64
from typing import (
Optional, List, Union
)

import sys
import os

from ...exceptions import (
Expand Down Expand Up @@ -92,7 +92,7 @@ def build_htlc(self, secret_hash: str, recipient_public_key: str, sender_public_
if use_script:

# Get current working directory path (like linux or unix path).
cwd: str = PurePosixPath(os.path.dirname(os.path.realpath(__file__))).__str__().replace("\\", "/")
cwd: str = os.path.dirname(sys.modules[__package__].__file__)

with open(f"{cwd}/contracts/htlc.equity", "r", encoding="utf-8") as htlc_equity_file:
htlc_script: str = "".join(htlc_equity_file.readlines()[-14:])
Expand Down
4 changes: 2 additions & 2 deletions swap/providers/xinfin/htlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from typing import (
Optional, Type, Union
)
from pathlib import PurePosixPath
from web3.types import Wei

import json
import sys
import os

from ...exceptions import (
Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self, contract_address: Optional[str] = None, network: str = config
)

# Get current working directory path (like linux or unix path).
cwd: str = PurePosixPath(os.path.dirname(os.path.realpath(__file__))).__str__().replace("\\", "/")
cwd: str = os.path.dirname(sys.modules[__package__].__file__)

if use_script:
solcx = __import__("solcx")
Expand Down

0 comments on commit 0ca8966

Please sign in to comment.