Skip to content

Commit 6182209

Browse files
authored
[lightapi/python] fix: update transaction field.
Problem: signer and recipient fields are still in plain text, to be consistent, it need convert to objects. Solution: Wrap signer and recipient into Publickey and Address objects.
1 parent 2385d6d commit 6182209

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

lightapi/python/symbollightapi/connector/NemConnector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def _map_to_transaction(transaction, block_height):
378378
common_args = {
379379
'transaction_hash': transaction['hash'],
380380
'height': block_height,
381-
'sender': tx_json['signer'],
381+
'sender': PublicKey(tx_json['signer']),
382382
'fee': tx_json['fee'],
383383
'timestamp': tx_json['timeStamp'],
384384
'deadline': tx_json['deadline'],

lightapi/python/symbollightapi/model/Transaction.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from collections import namedtuple
22

3+
from symbolchain.CryptoTypes import PublicKey
34
from symbolchain.nc import TransactionType
5+
from symbolchain.nem.Network import Address
46

57
from ..model.Exceptions import UnknownTransactionType
68

@@ -428,7 +430,7 @@ def _map_transfer_args(tx_json):
428430

429431
return {
430432
'amount': tx_json['amount'],
431-
'recipient': tx_json['recipient'],
433+
'recipient': Address(tx_json['recipient']),
432434
'message': message,
433435
'mosaics': mosaics,
434436
}
@@ -437,7 +439,7 @@ def _map_transfer_args(tx_json):
437439
def _map_account_key_link_args(tx_json):
438440
return {
439441
'mode': tx_json['mode'],
440-
'remote_account': tx_json['remoteAccount'],
442+
'remote_account': PublicKey(tx_json['remoteAccount']),
441443
}
442444

443445
@staticmethod
@@ -447,7 +449,7 @@ def _map_multisig_account_modification_args(tx_json):
447449
'modifications': [
448450
Modification(
449451
modification['modificationType'],
450-
modification['cosignatoryAccount'])
452+
PublicKey(modification['cosignatoryAccount']))
451453
for modification in tx_json['modifications']
452454
]
453455
}
@@ -461,7 +463,7 @@ def _map_multisig_transaction_args(self, tx_json, inner_hash):
461463
common_args = {
462464
'transaction_hash': None,
463465
'height': None,
464-
'sender': other_transaction['signer'],
466+
'sender': PublicKey(other_transaction['signer']),
465467
'fee': other_transaction['fee'],
466468
'timestamp': other_transaction['timeStamp'],
467469
'deadline': other_transaction['deadline'],
@@ -473,8 +475,8 @@ def _map_multisig_transaction_args(self, tx_json, inner_hash):
473475
CosignSignatureTransaction(
474476
signature['timeStamp'],
475477
signature['otherHash']['data'],
476-
signature['otherAccount'],
477-
signature['signer'],
478+
Address(signature['otherAccount']),
479+
PublicKey(signature['signer']),
478480
signature['fee'],
479481
signature['deadline'],
480482
signature['signature']
@@ -488,7 +490,7 @@ def _map_multisig_transaction_args(self, tx_json, inner_hash):
488490
@staticmethod
489491
def _map_namespace_registration_args(tx_json):
490492
return {
491-
'rental_fee_sink': tx_json['rentalFeeSink'],
493+
'rental_fee_sink': Address(tx_json['rentalFeeSink']),
492494
'rental_fee': tx_json['rentalFee'],
493495
'parent': tx_json['parent'],
494496
'namespace': tx_json['newPart'],
@@ -514,15 +516,15 @@ def _map_mosaic_definition_args(tx_json):
514516
if mosaic_levy:
515517
mosaic_levy = MosaicLevy(
516518
mosaic_levy['fee'],
517-
mosaic_levy['recipient'],
519+
Address(mosaic_levy['recipient']),
518520
mosaic_levy['type'],
519521
f'{mosaic_levy["mosaicId"]["namespaceId"]}.{mosaic_levy["mosaicId"]["name"]}'
520522
)
521523

522524
return {
523525
'creation_fee': tx_json['creationFee'],
524-
'creation_fee_sink': tx_json['creationFeeSink'],
525-
'creator': mosaic_definition['creator'],
526+
'creation_fee_sink': Address(tx_json['creationFeeSink']),
527+
'creator': PublicKey(mosaic_definition['creator']),
526528
'description': mosaic_definition['description'],
527529
'namespace_name': f'{mosaic_id["namespaceId"]}.{mosaic_id["name"]}',
528530
'properties': mosaic_properties,

lightapi/python/tests/connector/test_NemConnector.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,79 +1214,79 @@ async def test_can_try_wait_for_announced_transaction_confirmed_timeout(server):
12141214
AccountKeyLinkTransaction(
12151215
'306f20260a1b7af692834809d3e7d53edd41616d5076ac0fac6cfa75982185df',
12161216
2,
1217-
'22df5f43ee3739a10c346b3ec2d3878668c5514696be425f9067d3a11c777f1d',
1217+
PublicKey('22df5f43ee3739a10c346b3ec2d3878668c5514696be425f9067d3a11c777f1d'),
12181218
8000000,
12191219
73397,
12201220
83397,
12211221
'1b81379847241e45da86b27911e5c9a9192ec04f644d98019657d32838b49c14'
12221222
'3eaa4815a3028b80f9affdbf0b94cd620f7a925e02783dda67b8627b69ddf70e',
12231223
1,
1224-
'7195f4d7a40ad7e31958ae96c4afed002962229675a4cae8dc8a18e290618981'
1224+
PublicKey('7195f4d7a40ad7e31958ae96c4afed002962229675a4cae8dc8a18e290618981')
12251225
),
12261226
TransferTransaction(
12271227
'd6c9902cfa23dbbdd212d720f86391dd91d215bf77d806f03a6c2dd2e730628a',
12281228
2,
1229-
'8d07f90fb4bbe7715fa327c926770166a11be2e494a970605f2e12557f66c9b9',
1229+
PublicKey('8d07f90fb4bbe7715fa327c926770166a11be2e494a970605f2e12557f66c9b9'),
12301230
9000000,
12311231
73397,
12321232
83397,
12331233
'e0cc7f71e353ca0aaf2f009d74aeac5f97d4796b0f08c009058fb33d93c2e8ca'
12341234
'68c0b63e46ff125f43314014d324ac032d2c82996a6e47068b251f1d71fdd001',
12351235
180000040000000,
1236-
'NCOPERAWEWCD4A34NP5UQCCKEX44MW4SL3QYJYS5',
1236+
Address('NCOPERAWEWCD4A34NP5UQCCKEX44MW4SL3QYJYS5'),
12371237
('476f6f64206c75636b21', 1),
12381238
None
12391239
),
12401240
MultisigAccountModificationTransaction(
12411241
'cc64ca69bfa95db2ff7ac1e21fe6d27ece189c603200ebc9778d8bb80ca25c3c',
12421242
2,
1243-
'f41b99320549741c5cce42d9e4bb836d98c50ed5415d0c3c2912d1bb50e6a0e5',
1243+
PublicKey('f41b99320549741c5cce42d9e4bb836d98c50ed5415d0c3c2912d1bb50e6a0e5'),
12441244
40000000,
12451245
73397,
12461246
83397,
12471247
'81ff2235f9ad6f3f8adbc16051bf8691a45ee5ddcace4d6260ce9a2ae63dba59'
12481248
'4f2b486f25451a1f90da7f0e312d9e8570e4bc03798e58d19dec86feb4152307',
12491249
2,
12501250
[
1251-
(1, '1fbdbdde28daf828245e4533765726f0b7790e0b7146e2ce205df3e86366980b'),
1252-
(1, 'f94e8702eb1943b23570b1b83be1b81536df35538978820e98bfce8f999e2d37')
1251+
(1, PublicKey('1fbdbdde28daf828245e4533765726f0b7790e0b7146e2ce205df3e86366980b')),
1252+
(1, PublicKey('f94e8702eb1943b23570b1b83be1b81536df35538978820e98bfce8f999e2d37'))
12531253
]
12541254
),
12551255
NamespaceRegistrationTransaction(
12561256
'7e547e45cfc9c34809ce184db6ae7b028360c0f1492cc37b7b4d31c22af07dc3',
12571257
2,
1258-
'a700809530e5428066807ec0d34859c52e260fc60634aaac13e3972dcfc08736',
1258+
PublicKey('a700809530e5428066807ec0d34859c52e260fc60634aaac13e3972dcfc08736'),
12591259
150000,
12601260
73397,
12611261
83397,
12621262
'9fc70720d0333d7d8f9eb14ef45ce45a846d37e79cf7a4244b4db36dcb0d3dfe'
12631263
'0170daefbf4d30f92f343110a6f03a14aedcf7913e465a4a1cc199639169410a',
1264-
'NAMESPACEWH4MKFMBCVFERDPOOP4FK7MTBXDPZZA',
1264+
Address('NAMESPACEWH4MKFMBCVFERDPOOP4FK7MTBXDPZZA'),
12651265
100000000,
12661266
None,
12671267
'namespace'
12681268
),
12691269
MosaicDefinitionTransaction(
12701270
'4725e523e5d5a562121f38953d6da3ae695060533fc0c5634b31de29c3b766e1',
12711271
2,
1272-
'a700809530e5428066807ec0d34859c52e260fc60634aaac13e3972dcfc08736',
1272+
PublicKey('a700809530e5428066807ec0d34859c52e260fc60634aaac13e3972dcfc08736'),
12731273
150000,
12741274
73397,
12751275
83397,
12761276
'a80ccd44955ded7d35ee3aa011bfafd3f30cc746f63cb59a9d02171f908a0f4a'
12771277
'0294fcbba0b2838acd184daf1d9ae3c0f645308b442547156364192cd3d2d605',
12781278
10000000,
1279-
'NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS',
1280-
'a700809530e5428066807ec0d34859c52e260fc60634aaac13e3972dcfc08736',
1279+
Address('NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS'),
1280+
PublicKey('a700809530e5428066807ec0d34859c52e260fc60634aaac13e3972dcfc08736'),
12811281
'NEM namespace test',
12821282
(4, 3100000, False, True),
1283-
(500, 'NBRYCNWZINEVNITUESKUMFIENWKYCRUGNFZV25AV', 1, 'nem.xem'),
1283+
(500, Address('NBRYCNWZINEVNITUESKUMFIENWKYCRUGNFZV25AV'), 1, 'nem.xem'),
12841284
'namespace.test'
12851285
),
12861286
MosaicSupplyChangeTransaction(
12871287
'cb805b4499479135934e70452d12ad9ecc26c46a111fe0cdda8e09741d257708',
12881288
2,
1289-
'da04b4a1d64add6c70958d383f9d247af1aaa957cb89f15b2d059b278e0594d5',
1289+
PublicKey('da04b4a1d64add6c70958d383f9d247af1aaa957cb89f15b2d059b278e0594d5'),
12901290
150000,
12911291
73397,
12921292
83397,
@@ -1299,7 +1299,7 @@ async def test_can_try_wait_for_announced_transaction_confirmed_timeout(server):
12991299
MultisigTransaction(
13001300
'3375969dbc2aaae1cad0d89854d4f41b4fef553dbe9c7d39bdf72e3c538f98fe',
13011301
2,
1302-
'aa455d831430872feb0c6ae14265209182546c985a321c501be7fdc96ed04757',
1302+
PublicKey('aa455d831430872feb0c6ae14265209182546c985a321c501be7fdc96ed04757'),
13031303
500000,
13041304
73397,
13051305
83397,
@@ -1309,8 +1309,8 @@ async def test_can_try_wait_for_announced_transaction_confirmed_timeout(server):
13091309
CosignSignatureTransaction(
13101310
261593985,
13111311
'edcc8d1c48165f5b771087fbe3c4b4d41f5f8f6c4ce715e050b86fb4e7fdeb64',
1312-
'NAGJG3QFWYZ37LMI7IQPSGQNYADGSJZGJRD2DIYA',
1313-
'ae6754c70b7e3ba0c51617c8f9efd462d0bf680d45e09c3444e817643d277826',
1312+
Address('NAGJG3QFWYZ37LMI7IQPSGQNYADGSJZGJRD2DIYA'),
1313+
PublicKey('ae6754c70b7e3ba0c51617c8f9efd462d0bf680d45e09c3444e817643d277826'),
13141314
500000,
13151315
261680385,
13161316
'249bc2dbad96e827eabc991b59dff7f12cc27f3e0da8ab3db6a3201169431786'
@@ -1320,13 +1320,13 @@ async def test_can_try_wait_for_announced_transaction_confirmed_timeout(server):
13201320
TransferTransaction(
13211321
None,
13221322
None,
1323-
'fbae41931de6a0cc25153781321f3de0806c7ba9a191474bb9a838118c8de4d3',
1323+
PublicKey('fbae41931de6a0cc25153781321f3de0806c7ba9a191474bb9a838118c8de4d3'),
13241324
750000,
13251325
73397,
13261326
83397,
13271327
None,
13281328
150000000000,
1329-
'NBUH72UCGBIB64VYTAAJ7QITJ62BLISFFQOHVP65',
1329+
Address('NBUH72UCGBIB64VYTAAJ7QITJ62BLISFFQOHVP65'),
13301330
None,
13311331
None
13321332
),

0 commit comments

Comments
 (0)