forked from coccoinomane/web3cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_controller.py
More file actions
67 lines (62 loc) · 2.27 KB
/
Copy pathsend_controller.py
File metadata and controls
67 lines (62 loc) · 2.27 KB
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
from cement import ex
from web3cli.framework.controller import Controller
from web3cli.helpers import args
from web3cli.helpers.render import render
from web3cli.helpers.send import send_coin_or_token
from web3core.helpers.misc import to_number, yes_or_exit
from web3core.helpers.resolve import resolve_address
class SendController(Controller):
"""Handler of the `w3 send` command"""
class Meta:
label = "send"
help = "send native coins, tokens and NFTs"
stacked_type = "embedded"
stacked_on = "base"
@ex(
help="Send a coin or token to the given address, and show the transaction hash",
arguments=[
(
["to"],
{
"help": "receiver of the funds; can be an actual address or an address tag",
},
),
(["amount"], {"help": "how much to send"}),
(
["ticker"],
{"help": "ticker of the coin or token to send"},
),
(
["unit"],
{
"help": "optionally specify the unit to use. For native-coins: wei, gwei, etc. For tokens: specify 'smallest' to send using the smallest unit of the token.",
"nargs": "?",
},
),
*args.chain_and_rpc(),
*args.signer_and_gas(),
args.force(),
],
)
def send(self) -> None:
# Parse arguments
to_address = resolve_address(self.app.pargs.to, chain=self.app.chain.name)
amount = to_number(self.app.pargs.amount)
ticker = self.app.pargs.ticker.lower()
if not self.app.pargs.force:
what = f"{amount} {ticker}"
if self.app.pargs.unit:
what = f"{amount} {self.app.pargs.unit} unit(s) of {ticker}"
print(
f"You are about to send {what} on the {self.app.chain.name} chain from {self.app.signer.address} to {to_address}."
)
yes_or_exit(logger=self.app.log.info)
# Send
tx_hash = send_coin_or_token(
self.app,
ticker=ticker,
to=to_address,
amount=amount,
unit=self.app.pargs.unit,
)
render(self.app, tx_hash)