Skip to content

Commit

Permalink
Add reason of refund in memo
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 22, 2019
1 parent b26d28e commit 4afea88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/escrow/blockchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ async def get_limits(self, asset: str) -> InsuranceLimits:
"""

@abstractmethod
async def transfer(self, to: str, amount: Decimal, asset: str) -> str:
async def transfer(
self, to: str, amount: Decimal, asset: str, memo: str = ""
) -> str:
"""Transfer ``asset`` from ``self.address``.
:param to: Address assets are transferred to.
Expand Down Expand Up @@ -245,7 +247,7 @@ async def _refund_callback(

user = offer["init"] if offer["type"] == "buy" else offer["counter"]
answer = _("There are mistakes in your transfer:", locale=user["locale"])

points = []
for reason in reasons:
if reason == "asset":
point = _("wrong asset", locale=user["locale"])
Expand All @@ -255,6 +257,7 @@ async def _refund_callback(
point = _("wrong memo", locale=user["locale"])
else:
continue
points.append(point)
answer += "\n• " + point

answer += "\n\n" + _(
Expand All @@ -266,7 +269,12 @@ async def _refund_callback(
{"_id": offer["_id"]}, {"$set": {"transaction_time": time()}}
)
if is_confirmed:
trx_url = await self.transfer(from_address, amount, asset)
trx_url = await self.transfer(
from_address,
amount,
asset,
memo="reason of refund: " + ", ".join(points),
)
answer = markdown.link(
_("Transaction is refunded.", locale=user["locale"]), trx_url
)
Expand Down
3 changes: 2 additions & 1 deletion src/escrow/blockchain/golos_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def get_limits(self, asset: str):
limits = {"GOLOS": InsuranceLimits(Decimal("10000"), Decimal("100000"))}
return limits.get(asset)

async def transfer(self, to: str, amount: Decimal, asset: str):
async def transfer(self, to: str, amount: Decimal, asset: str, memo: str = ""):
with open(Config.WIF_FILENAME) as wif_file:
transaction = await get_running_loop().run_in_executor(
None,
Expand All @@ -124,6 +124,7 @@ async def transfer(self, to: str, amount: Decimal, asset: str):
self.address,
json.load(wif_file)["golos"],
asset,
memo,
)
return self.trx_url(transaction["id"])

Expand Down

0 comments on commit 4afea88

Please sign in to comment.