XMR compat: basic transaction support

- This functionality is work-in-progress: sweep transactions, spending to
  MMGen IDs and certain options are not supported yet.

- The `--autosign` option is required.  It may be set in the config file.

- On the offline signing machine, `--xmrwallet-compat` is required, or it
  may be set in the config file.  On the online machine, the option is
  required to permit interoperability with `mmgen-xmrwallet`.

- Note that transactions created with `mmgen-txcreate` must be sent with
  `mmgen-txsend`, not `mmgen-xmrwallet submit`, which looks for signed
  transactions in a different directory on the removable device.

- Signed or unsigned transactions may be aborted with `mmgen-txsend --abort`.

- Compat mode uses `mmgen-xmrwallet` as its backend, and that command is still
  required for all operations beyond simple create-sign-send to address.  For
  details, invoke `mmgen-xmrwallet --help`.

Sample workflow:

    $ mmgen-txcreate --coin=xmr XMR_ADDRESS,AMOUNT

    (remove - insert - wait for signing - remove - insert)

    $ mmgen-txsend

Testing/demo:

    $ test/cmdtest.py --coin=xmr -e xmr_compat
This commit is contained in:
The MMGen Project 2025-12-01 16:54:36 +00:00
commit cb99e13cd5
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
30 changed files with 366 additions and 58 deletions

View file

@ -189,6 +189,11 @@ class Signable:
cfg = self.cfg,
filename = f,
automount = self.automount)
if tx1.proto.coin == 'XMR':
ctx = Signable.xmr_compat_transaction(self.parent)
for k in ('desc', 'print_summary', 'print_bad_list'):
setattr(self, k, getattr(ctx, k))
return await ctx.sign(f, compat_call=True)
if tx1.proto.sign_mode == 'daemon':
from .rpc import rpc_init
tx1.rpc = await rpc_init(self.cfg, tx1.proto, ignore_wallet=True)
@ -357,7 +362,7 @@ class Signable:
sigext = 'sigtx'
subext = 'subtx'
async def sign(self, f):
async def sign(self, f, compat_call=False):
from . import xmrwallet
from .xmrwallet.file.tx import MoneroMMGenTX
tx1 = MoneroMMGenTX.Completed(self.parent.xmrwallet_cfg, f)
@ -365,11 +370,19 @@ class Signable:
'sign',
self.parent.xmrwallet_cfg,
infile = str(self.parent.wallet_files[0]), # MMGen wallet file
wallets = str(tx1.src_wallet_idx))
wallets = str(tx1.src_wallet_idx),
compat_call = compat_call)
tx2 = await m.main(f, restart_daemon=self.need_daemon_restart(m, tx1.src_wallet_idx))
tx2.write(ask_write=False)
return tx2
class xmr_compat_transaction(xmr_transaction):
desc = 'Monero compat transaction'
dir_name = 'txauto_dir'
rawext = 'arawtx'
sigext = 'asigtx'
subext = 'asubtx'
class xmr_wallet_outputs_file(xmr_signable, base):
desc = 'Monero wallet outputs file'
dir_name = 'xmr_outputs_dir'
@ -553,8 +566,10 @@ class Autosign:
self.signables += Signable.non_xmr_signables
if self.have_xmr:
self.dirs |= self.xmr_dirs
self.signables += Signable.xmr_signables
self.dirs |= self.xmr_dirs | (
{'txauto_dir': 'txauto'} if cfg.xmrwallet_compat and self.xmr_only else {})
self.signables += Signable.xmr_signables + (
('automount_transaction',) if cfg.xmrwallet_compat and self.xmr_only else ())
for name, path in self.dirs.items():
setattr(self, name, self.mountpoint / path)

View file

@ -153,7 +153,8 @@
# monero_wallet_rpc_password passw0rd
# Configure mmgen-xmrwallet for compatibility with mmgen-tx{create,sign,send}
# family of commands (equivalent to mmgen-xmrwallet --compat option)
# family of commands (equivalent to mmgen-xmrwallet --compat option). This
# option also enables signing of XMR compat transactions by `mmgen-autosign`.
# xmrwallet_compat true
#######################################################################

View file

@ -1 +1 @@
November 2025
December 2025

View file

@ -1 +1 @@
16.1.dev19
16.1.dev20

View file

@ -22,6 +22,8 @@ class help_notes:
match self.proto.base_proto:
case 'Bitcoin':
return '[ADDR,AMT ... | DATA_SPEC] ADDR [addr file ...]'
case 'Monero':
return 'ADDR,AMT'
case _:
return 'ADDR,AMT [addr file ...]'

View file

@ -56,6 +56,15 @@ EXAMPLES:
$ {gc.prog_name} {mmtype}
"""
case 'Monero':
return f"""
EXAMPLES:
Send 0.123 {proto.coin} to an external {proto.name} address:
$ {gc.prog_name} {sample_addr},0.123
"""
case _:
return f"""
EXAMPLES:

View file

@ -22,7 +22,8 @@ mmgen-txcreate: Create a cryptocoin transaction with MMGen- and/or non-MMGen
"""
from .cfg import gc, Config
from .util import Msg, fmt_list, async_run
from .util import Msg, fmt_list, fmt_dict, async_run
from .xmrwallet import tx_priorities
target = gc.prog_name.split('-')[1].removesuffix('create')
@ -72,6 +73,10 @@ opts_data = {
b- -L, --autochg-ignore-labels Ignore labels when autoselecting change addresses
-- -m, --minconf= n Minimum number of confirmations required to spend
+ outputs (default: 1)
m- -p, --priority=N Specify an integer priority ‘N’ for inclusion of trans-
+ action in blockchain (higher number means higher fee).
+ Valid parameters: {tp}.
+ If option is omitted, the default priority will be used
-- -q, --quiet Suppress warnings; overwrite files without prompting
-s -r, --stream-interval=N Set block interval for streaming swap (default: {si})
bt -R, --no-rbf Make transaction non-replaceable (non-replace-by-fee
@ -101,6 +106,7 @@ opts_data = {
a_info = help_notes('account_info_desc'),
fu = help_notes('rel_fee_desc'),
fl = help_notes('fee_spec_letters', use_quotes=True),
tp = fmt_dict(tx_priorities, fmt='equal_compact'),
si = help_notes('stream_interval'),
fe_all = fmt_list(cfg._autoset_opts['fee_estimate_mode'].choices, fmt='no_spc'),
fe_dfl = cfg._autoset_opts['fee_estimate_mode'].choices[0],
@ -132,7 +138,7 @@ async def main():
if cfg.autosign:
from .tx.util import mount_removable_device
from .autosign import Signable
asi = mount_removable_device(cfg)
asi = mount_removable_device(cfg, add_cfg={'xmrwallet_compat': True})
Signable.automount_transaction(asi).check_create_ok()
if target == 'swaptx':
@ -149,10 +155,11 @@ async def main():
locktime = int(cfg.locktime or 0),
do_info = cfg.info)
tx2.file.write(
outdir = asi.txauto_dir if cfg.autosign else None,
ask_write = not cfg.yes,
ask_overwrite = not cfg.yes,
ask_write_default_yes = False)
if not tx1.is_compat:
tx2.file.write(
outdir = asi.txauto_dir if cfg.autosign else None,
ask_write = not cfg.yes,
ask_overwrite = not cfg.yes,
ask_write_default_yes = False)
async_run(cfg, main)

View file

@ -131,6 +131,9 @@ async def main():
automount = cfg.autosign,
quiet_open = True)
if tx.is_compat:
return await tx.compat_send()
cfg = Config({'_clone': cfg, 'proto': tx.proto, 'coin': tx.proto.coin})
if cfg.tx_proxy:

View file

@ -308,9 +308,10 @@ class UserOpts(Opts):
br --rpc-user=USER Authenticate to coin daemon using username USER
br --rpc-password=PASS Authenticate to coin daemon using password PASS
Rr --rpc-backend=backend Use backend 'backend' for JSON-RPC communications
mr --monero-wallet-rpc-user=USER Monero wallet RPC username
mr --monero-wallet-rpc-password=USER Monero wallet RPC password
mr --monero-daemon=HOST:PORT Connect to the monerod at HOST:PORT
-r --monero-wallet-rpc-user=USER Monero wallet RPC username
-r --monero-wallet-rpc-password=USER Monero wallet RPC password
-r --monero-daemon=HOST:PORT Connect to the monerod at HOST:PORT
-r --xmrwallet-compat Enable XMR compatibility mode
Rr --aiohttp-rpc-queue-len=N Use N simultaneous RPC connections with aiohttp
-p --regtest=0|1 Disable or enable regtest mode
-- --testnet=0|1 Disable or enable testnet

View file

@ -37,9 +37,10 @@ class mainnet(CoinProtocol.RPC, CoinProtocol.DummyWIF, CoinProtocol.Base):
pubkey_type = 'monero' # required by DummyWIF
avg_bdi = 120
privkey_len = 32
mmcaps = ('rpc',)
mmcaps = ('rpc', 'tw')
coin_amt = 'XMRAmt'
sign_mode = 'standalone'
has_usr_fee = False
coin_cfg_opts = (
'ignore_daemon_version',

View file

@ -25,6 +25,7 @@ from ....tw.unspent import TwUnspentOutputs
class MoneroTwView:
is_account_based = True
item_desc = 'account'
nice_addr_w = {'addr': 20}
total = None

17
mmgen/proto/xmr/tx/base.py Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
# Licensed under the GNU General Public License, Version 3:
# https://www.gnu.org/licenses
# Public project repositories:
# https://github.com/mmgen/mmgen-wallet
# https://gitlab.com/mmgen/mmgen-wallet
"""
proto.xmr.tx.base: Monero base transaction class
"""
class Base:
is_compat = True
has_comment = False

27
mmgen/proto/xmr/tx/completed.py Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
# Licensed under the GNU General Public License, Version 3:
# https://www.gnu.org/licenses
# Public project repositories:
# https://github.com/mmgen/mmgen-wallet
# https://gitlab.com/mmgen/mmgen-wallet
"""
proto.xmr.tx.completed: Monero completed transaction class
"""
from ....cfg import Config
from .base import Base
class Completed(Base):
def __init__(self, cfg, *args, proto, filename, **kwargs):
self.cfg = Config({
'_clone': cfg,
'coin': 'XMR',
'network': proto.network})
self.proto = proto
self.filename = filename

55
mmgen/proto/xmr/tx/new.py Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
# Licensed under the GNU General Public License, Version 3:
# https://www.gnu.org/licenses
# Public project repositories:
# https://github.com/mmgen/mmgen-wallet
# https://gitlab.com/mmgen/mmgen-wallet
"""
proto.xmr.tx.new: Monero new transaction class
"""
from ....tx.new import New as TxNew
from .base import Base
class New(Base, TxNew):
async def get_input_addrs_from_inputs_opt(self):
return [] # TODO
async def set_gas(self):
pass
async def get_fee(self, fee, outputs_sum, start_fee_desc):
return True
def copy_inputs_from_tw(self, tw_unspent_data):
self.inputs = tw_unspent_data
def get_unspent_nums_from_user(self, accts_data):
from ....util import msg, is_int
from ....ui import line_input
prompt = 'Enter an account number to spend from: '
while True:
if reply := line_input(self.cfg, prompt).strip():
if is_int(reply) and 1 <= int(reply) <= len(accts_data):
return [int(reply)]
msg(f'Account number must be an integer between 1 and {len(accts_data)} inclusive')
async def compat_create(self):
from ....xmrwallet import op as xmrwallet_op
i = self.inputs[0]
o = self.outputs[0]
op = xmrwallet_op(
'transfer',
self.cfg,
None,
None,
spec = f'{i.idx}:{i.acct_idx}:{o.addr},{o.amt}',
compat_call = True)
await op.restart_wallet_daemon()
return await op.main()

32
mmgen/proto/xmr/tx/online.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
# Licensed under the GNU General Public License, Version 3:
# https://www.gnu.org/licenses
# Public project repositories:
# https://github.com/mmgen/mmgen-wallet
# https://gitlab.com/mmgen/mmgen-wallet
"""
proto.xmr.tx.online: Monero online signed transaction class
"""
from .completed import Completed
class OnlineSigned(Completed):
async def compat_send(self):
from ....xmrwallet import op as xmrwallet_op
op = xmrwallet_op('submit', self.cfg, self.filename, None, compat_call=True)
await op.restart_wallet_daemon()
return await op.main()
class Sent(OnlineSigned):
pass
class AutomountOnlineSigned(OnlineSigned):
pass
class AutomountSent(AutomountOnlineSigned):
pass

21
mmgen/proto/xmr/tx/unsigned.py Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
# Licensed under the GNU General Public License, Version 3:
# https://www.gnu.org/licenses
# Public project repositories:
# https://github.com/mmgen/mmgen-wallet
# https://gitlab.com/mmgen/mmgen-wallet
"""
proto.xmr.tx.unsigned: Monero unsigned transaction class
"""
from .completed import Completed
class Unsigned(Completed):
pass
class AutomountUnsigned(Unsigned):
pass

View file

@ -80,6 +80,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
def do(method, data, cw, fs, color, fmt_method):
return [l.rstrip() for l in method(data, cw, fs, color, fmt_method)]
is_account_based = False
has_age = False
has_used = False
has_wallet = True

View file

@ -81,6 +81,8 @@ class Base(MMGenObject):
signed = False
is_bump = False
is_swap = False
is_compat = False
has_comment = True
swap_attrs = {
'swap_proto': None,
'swap_quote_expiry': None,

View file

@ -25,6 +25,10 @@ import os, json
from ..util import ymsg, make_chksum_6, die
from ..obj import MMGenObject, HexStr, MMGenTxID, CoinTxID, MMGenTxComment
def get_monero_proto(tx, data):
from ..protocol import init_proto
return init_proto(tx.cfg, 'XMR', network=data['MoneroMMGenTX']['data']['network'])
class txdata_json_encoder(json.JSONEncoder):
def default(self, o):
if type(o).__name__.endswith('Amt'):
@ -90,6 +94,9 @@ class MMGenTxFile(MMGenObject):
tx = self.tx
tx.file_format = 'json'
outer_data = json.loads(data)
if 'MoneroMMGenTX' in outer_data:
tx.proto = get_monero_proto(tx, outer_data)
return None
data = outer_data[self.data_label]
if outer_data['chksum'] != make_chksum_6(json_dumps(data)):
chk = make_chksum_6(json_dumps(data))

View file

@ -245,6 +245,9 @@ class New(Base):
is_chg = not a.amt,
is_vault = a.is_vault)
if self.is_compat:
return
if self.chg_idx is None:
die(2,
fmt(self.msg_no_change_output.format(self.dcoin)).strip()
@ -386,7 +389,7 @@ class New(Base):
async def get_inputs(self, outputs_sum):
data = self.twuo.data
data = self.twuo.accts_data if self.twuo.is_account_based else self.twuo.data
sel_nums = (
self.get_unspent_nums_from_inputs_opt if self.cfg.inputs else
@ -399,10 +402,10 @@ class New(Base):
' '.join(str(n) for n in sel_nums)))
sel_unspent = MMGenList(data[i-1] for i in sel_nums)
if not await self.precheck_sufficient_funds(
if not (self.is_compat or await self.precheck_sufficient_funds(
sum(s.amt for s in sel_unspent),
sel_unspent,
outputs_sum):
outputs_sum)):
return False
self.copy_inputs_from_tw(sel_unspent) # makes self.inputs
@ -456,13 +459,16 @@ class New(Base):
cmd_args, addrfile_args = self.get_addrfiles_from_cmdline(cmd_args)
if self.is_swap:
cmd_args = await self.process_swap_cmdline_args(cmd_args, addrfile_args)
from ..rpc import rpc_init
self.rpc = await rpc_init(self.cfg, self.proto)
from ..addrdata import TwAddrData
await self.process_cmdline_args(
cmd_args,
self.get_addrdata_from_files(self.proto, addrfile_args),
await TwAddrData(self.cfg, self.proto, twctl=self.twctl))
if self.is_compat:
await self.process_cmdline_args(cmd_args, None, None)
else:
from ..rpc import rpc_init
self.rpc = await rpc_init(self.cfg, self.proto)
from ..addrdata import TwAddrData
await self.process_cmdline_args(
cmd_args,
self.get_addrdata_from_files(self.proto, addrfile_args),
await TwAddrData(self.cfg, self.proto, twctl=self.twctl))
if not self.is_bump:
self.twuo = await TwUnspentOutputs(
@ -510,13 +516,12 @@ class New(Base):
desc)) is not None:
break
self.check_non_mmgen_inputs(caller=caller)
if not self.is_compat:
self.check_non_mmgen_inputs(caller=caller)
self.update_change_output(funds_left)
self.check_chg_addr_is_wallet_addr()
self.update_change_output(funds_left)
self.check_chg_addr_is_wallet_addr()
if not self.cfg.yes:
if self.has_comment and not self.cfg.yes:
self.add_comment() # edits an existing comment
if self.is_swap:
@ -524,6 +529,9 @@ class New(Base):
if time.time() > self.swap_quote_refresh_time + self.swap_quote_refresh_timeout:
await self.update_vault_output(self.vault_output.amt)
if self.is_compat:
return await self.compat_create()
await self.create_serialized(locktime=locktime) # creates self.txid too
self.add_timestamp()

Some files were not shown because too many files have changed in this diff Show more