-
Notifications
You must be signed in to change notification settings - Fork 5
/
cleanAddress.py
97 lines (86 loc) · 2.9 KB
/
cleanAddress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import cardano_cli_helper as cli
import argparse
from os.path import exists
import copy # For dictionary deepcopy
def main(paymentAddrFile, paymentSkeyFile, garbageAddrFile,
policyIDToKeepList, network, era):
if exists(paymentAddrFile):
with open(paymentAddrFile, 'r') as file:
paymentAddr = file.read().strip()
else:
paymentAddr = paymentAddrFile.strip()
assert exists(paymentSkeyFile), "ERROR: Payment skey file does not exist."
if exists(garbageAddrFile):
with open(garbageAddrFile, 'r') as file:
garbageAddr = file.read().strip()
else:
garbageAddr = garbageAddrFile.strip()
utxo_limit = 200 # Ensures that the tx can fit in a block
# TODO: The number should be better calculated in bytes though
utxos = cli.getAddrUTxOs(paymentAddr, network, utxo_limit)
dictWallet = cli.getTokenListFromTxHash(utxos)
ttlSlot = cli.queryTip('slot', network) + 1000
destinationDict = copy.deepcopy(dictWallet)
destinationDict.pop("ADA", None)
returnDict = {"ADA": dictWallet["ADA"]}
for policy in policyIDToKeepList:
if policy in dictWallet.keys():
destinationDict.pop(policy, None)
returnDict[policy] = dictWallet[policy]
cli.buildSendTokensToOneDestinationTx(
utxos, paymentAddr, ttlSlot, garbageAddr,
0, destinationDict, returnDict, network, era=era
)
cli.signTx([paymentSkeyFile], network=network)
print(cli.submitSignedTx(network=network))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'-A', '--payment-addr',
default='account1.addr',
dest='payment_addr',
help='Provide payment address or location of payment address file.',
type=str
)
parser.add_argument(
'-K', '--payment-skey-file',
default='account1.skey',
dest='payment_skey_file',
help='Provide location of payment skey file.',
type=str
)
parser.add_argument(
'-D', '--destination',
default='garbage.addr',
dest='destination',
help='Provide location destination address file or string.',
type=str
)
parser.add_argument(
'-T', '--keep-token-policy-id',
default=[],
dest='keepPolicyIDList',
nargs='+',
help='List of tokens to send',
type=str)
parser.add_argument(
'-N', '--network',
default='testnet-magic 2',
dest='network',
help='Provide cardano network.',
type=str
)
parser.add_argument(
'-E', '--era',
default='conway',
dest='era',
help='Provide cardano era.',
type=str
)
args = parser.parse_args()
main(args.payment_addr,
args.payment_skey_file,
args.destination,
args.keepPolicyIDList,
args.network,
args.era)