Skip to content

Commit 590be17

Browse files
authored
[LABS-161] Add a method for creating outgoing transactions (#20209)
* Add a method for creating outgoing transactions * Fix some oversights wrt wallet_id
1 parent 810b9cf commit 590be17

File tree

10 files changed

+116
-247
lines changed

10 files changed

+116
-247
lines changed

chia/_tests/wallet/test_wallet.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
from chia.util.bech32m import encode_puzzle_hash
2222
from chia.util.byte_types import hexstr_to_bytes
2323
from chia.util.errors import Err
24-
from chia.wallet.conditions import ConditionValidTimes
2524
from chia.wallet.derive_keys import master_sk_to_wallet_sk
2625
from chia.wallet.estimate_fees import estimate_fees
2726
from chia.wallet.puzzles.clawback.metadata import AutoClaimSettings
28-
from chia.wallet.transaction_record import TransactionRecord
2927
from chia.wallet.util.compute_additions import compute_additions
3028
from chia.wallet.util.query_filter import TransactionTypeFilter
3129
from chia.wallet.util.transaction_type import TransactionType
@@ -1706,26 +1704,15 @@ async def test_wallet_prevent_fee_theft(self, wallet_environments: WalletTestFra
17061704

17071705
# get a legit signature
17081706
stolen_sb, _ = await wallet.wallet_state_manager.sign_bundle([stolen_cs])
1709-
name = stolen_sb.name()
1710-
stolen_tx = TransactionRecord(
1711-
confirmed_at_height=uint32(0),
1712-
created_at_time=uint64(0),
1713-
to_puzzle_hash=bytes32(32 * b"0"),
1714-
to_address=encode_puzzle_hash(bytes32(32 * b"0"), "txch"),
1707+
stolen_tx = wallet.wallet_state_manager.new_outgoing_transaction(
1708+
wallet_id=wallet.id(),
1709+
puzzle_hash=bytes32.zeros,
17151710
amount=uint64(0),
1716-
fee_amount=uint64(0),
1717-
confirmed=False,
1718-
sent=uint32(0),
1711+
fee=uint64(0),
17191712
spend_bundle=stolen_sb,
17201713
additions=[],
17211714
removals=[],
1722-
wallet_id=wallet.id(),
1723-
sent_to=[],
1724-
trade_id=None,
1725-
type=uint32(TransactionType.OUTGOING_TX.value),
1726-
name=name,
1727-
memos={},
1728-
valid_times=ConditionValidTimes(),
1715+
name=stolen_sb.name(),
17291716
)
17301717
[stolen_tx] = await wallet.wallet_state_manager.add_pending_transactions([stolen_tx])
17311718

chia/data_layer/data_layer_wallet.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import dataclasses
44
import logging
5-
import time
65
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast
76

87
from chia_rs import BlockRecord, CoinSpend, CoinState, G1Element, G2Element
@@ -29,7 +28,6 @@
2928
CreateCoin,
3029
CreateCoinAnnouncement,
3130
UnknownCondition,
32-
parse_timelock_info,
3331
)
3432
from chia.wallet.db_wallet.db_wallet_puzzles import (
3533
ACS_MU,
@@ -52,9 +50,7 @@
5250
from chia.wallet.trading.offer import NotarizedPayment, Offer
5351
from chia.wallet.transaction_record import TransactionRecord
5452
from chia.wallet.util.compute_additions import compute_additions
55-
from chia.wallet.util.compute_memos import compute_memos
5653
from chia.wallet.util.merkle_utils import _simplify_merkle_proof
57-
from chia.wallet.util.transaction_type import TransactionType
5854
from chia.wallet.util.wallet_sync_utils import fetch_coin_spend, fetch_coin_spend_for_coin_state
5955
from chia.wallet.util.wallet_types import WalletType
6056
from chia.wallet.wallet import Wallet
@@ -556,25 +552,16 @@ async def create_update_state_spend(
556552
if announce_new_state:
557553
spend_bundle = WalletSpendBundle([coin_spend, second_coin_spend], spend_bundle.aggregated_signature)
558554

559-
dl_tx = TransactionRecord(
560-
confirmed_at_height=uint32(0),
561-
created_at_time=uint64(time.time()),
562-
to_puzzle_hash=new_puz_hash,
563-
to_address=self.wallet_state_manager.encode_puzzle_hash(new_puz_hash),
555+
dl_tx = self.wallet_state_manager.new_outgoing_transaction(
556+
wallet_id=self.id(),
557+
puzzle_hash=new_puz_hash,
564558
amount=uint64(singleton_record.lineage_proof.amount),
565-
fee_amount=fee,
566-
confirmed=False,
567-
sent=uint32(10),
559+
fee=fee,
568560
spend_bundle=spend_bundle,
569561
additions=spend_bundle.additions(),
570562
removals=spend_bundle.removals(),
571-
memos=compute_memos(spend_bundle),
572-
wallet_id=self.id(),
573-
sent_to=[],
574-
trade_id=None,
575-
type=uint32(TransactionType.OUTGOING_TX.value),
576563
name=singleton_record.coin_id,
577-
valid_times=parse_timelock_info(extra_conditions),
564+
extra_conditions=extra_conditions,
578565
)
579566
assert dl_tx.spend_bundle is not None
580567
if fee > 0:
@@ -751,25 +738,16 @@ async def delete_mirror(
751738

752739
async with action_scope.use() as interface:
753740
interface.side_effects.transactions.append(
754-
TransactionRecord(
755-
confirmed_at_height=uint32(0),
756-
created_at_time=uint64(time.time()),
757-
to_puzzle_hash=new_puzhash,
758-
to_address=self.wallet_state_manager.encode_puzzle_hash(new_puzhash),
741+
self.wallet_state_manager.new_outgoing_transaction(
742+
wallet_id=self.id(),
743+
puzzle_hash=new_puzhash,
759744
amount=uint64(mirror_coin.amount),
760-
fee_amount=fee,
761-
confirmed=False,
762-
sent=uint32(10),
745+
fee=fee,
763746
spend_bundle=mirror_bundle,
764747
additions=mirror_bundle.additions(),
765748
removals=mirror_bundle.removals(),
766-
memos=compute_memos(mirror_bundle),
767-
wallet_id=self.id(), # This is being called before the wallet is created so we're using a ID of 0
768-
sent_to=[],
769-
trade_id=None,
770-
type=uint32(TransactionType.OUTGOING_TX.value),
771749
name=mirror_bundle.name(),
772-
valid_times=parse_timelock_info(extra_conditions),
750+
extra_conditions=extra_conditions,
773751
)
774752
)
775753

chia/pools/pool_wallet.py

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import dataclasses
44
import logging
5-
import time
65
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast
76

87
from chia_rs import CoinSpend, G1Element, G2Element
@@ -41,11 +40,10 @@
4140
from chia.types.blockchain_format.coin import Coin
4241
from chia.types.blockchain_format.program import Program
4342
from chia.types.coin_spend import make_spend
44-
from chia.wallet.conditions import AssertCoinAnnouncement, Condition, ConditionValidTimes
43+
from chia.wallet.conditions import AssertCoinAnnouncement, Condition
4544
from chia.wallet.puzzles.singleton_top_layer import SINGLETON_LAUNCHER
4645
from chia.wallet.transaction_record import TransactionRecord
4746
from chia.wallet.util.compute_additions import compute_additions
48-
from chia.wallet.util.transaction_type import TransactionType
4947
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG, TXConfig
5048
from chia.wallet.util.wallet_types import WalletType
5149
from chia.wallet.wallet import Wallet
@@ -523,25 +521,15 @@ async def generate_travel_transactions(self, fee: uint64, action_scope: WalletAc
523521

524522
async with action_scope.use() as interface:
525523
interface.side_effects.transactions.append(
526-
TransactionRecord(
527-
confirmed_at_height=uint32(0),
528-
created_at_time=uint64(time.time()),
529-
to_puzzle_hash=new_full_puzzle.get_tree_hash(),
530-
to_address=self.wallet_state_manager.encode_puzzle_hash(new_full_puzzle.get_tree_hash()),
524+
self.wallet_state_manager.new_outgoing_transaction(
525+
wallet_id=self.id(),
526+
puzzle_hash=new_full_puzzle.get_tree_hash(),
531527
amount=uint64(1),
532-
fee_amount=fee,
533-
confirmed=False,
534-
sent=uint32(0),
528+
fee=fee,
535529
spend_bundle=unsigned_spend_bundle,
536530
additions=unsigned_spend_bundle.additions(),
537531
removals=unsigned_spend_bundle.removals(),
538-
wallet_id=self.id(),
539-
sent_to=[],
540-
trade_id=None,
541-
memos={},
542-
type=uint32(TransactionType.OUTGOING_TX.value),
543532
name=unsigned_spend_bundle.name(),
544-
valid_times=ConditionValidTimes(),
545533
)
546534
)
547535

@@ -793,29 +781,18 @@ async def claim_pool_rewards(
793781
),
794782
)
795783

796-
current_time = uint64(time.time())
797784
# The claim spend, minus the fee amount from the main wallet
798785
async with action_scope.use() as interface:
799786
interface.side_effects.transactions.append(
800-
TransactionRecord(
801-
confirmed_at_height=uint32(0),
802-
created_at_time=current_time,
803-
to_puzzle_hash=current_state.current.target_puzzle_hash,
804-
to_address=self.wallet_state_manager.encode_puzzle_hash(current_state.current.target_puzzle_hash),
787+
self.wallet_state_manager.new_outgoing_transaction(
788+
wallet_id=uint32(self.wallet_id),
789+
puzzle_hash=current_state.current.target_puzzle_hash,
805790
amount=uint64(total_amount),
806-
fee_amount=fee, # This will not be double counted in self.standard_wallet
807-
confirmed=False,
808-
sent=uint32(0),
791+
fee=fee,
809792
spend_bundle=claim_spend,
810793
additions=[add for add in claim_spend.additions() if add.amount == last_solution.coin.amount],
811794
removals=claim_spend.removals(),
812-
wallet_id=uint32(self.wallet_id),
813-
sent_to=[],
814-
memos={},
815-
trade_id=None,
816-
type=uint32(TransactionType.OUTGOING_TX.value),
817795
name=claim_spend.name(),
818-
valid_times=ConditionValidTimes(),
819796
)
820797
)
821798

chia/wallet/cat_wallet/cat_wallet.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
CreateCoin,
4040
CreateCoinAnnouncement,
4141
UnknownCondition,
42-
parse_timelock_info,
4342
)
4443
from chia.wallet.derivation_record import DerivationRecord
4544
from chia.wallet.lineage_proof import LineageProof
@@ -49,7 +48,6 @@
4948
from chia.wallet.transaction_record import TransactionRecord
5049
from chia.wallet.uncurried_puzzle import uncurry_puzzle
5150
from chia.wallet.util.compute_additions import compute_additions_with_cost
52-
from chia.wallet.util.compute_memos import compute_memos
5351
from chia.wallet.util.curry_and_treehash import curry_and_treehash
5452
from chia.wallet.util.transaction_type import TransactionType
5553
from chia.wallet.util.wallet_sync_utils import fetch_coin_spend_for_coin_state
@@ -794,25 +792,16 @@ async def generate_signed_transaction(
794792
removal for tx in interface.side_effects.transactions for removal in tx.additions
795793
}
796794
interface.side_effects.transactions.append(
797-
TransactionRecord(
798-
confirmed_at_height=uint32(0),
799-
created_at_time=uint64(time.time()),
800-
to_puzzle_hash=puzzle_hashes[0],
801-
to_address=self.wallet_state_manager.encode_puzzle_hash(puzzle_hashes[0]),
795+
self.wallet_state_manager.new_outgoing_transaction(
796+
wallet_id=self.id(),
797+
puzzle_hash=puzzle_hashes[0],
802798
amount=uint64(payment_sum),
803-
fee_amount=fee,
804-
confirmed=False,
805-
sent=uint32(0),
799+
fee=fee,
806800
spend_bundle=spend_bundle,
807801
additions=list(set(spend_bundle.additions()) - other_tx_additions),
808802
removals=list(set(spend_bundle.removals()) - other_tx_removals),
809-
wallet_id=self.id(),
810-
sent_to=[],
811-
trade_id=None,
812-
type=uint32(TransactionType.OUTGOING_TX.value),
813803
name=spend_bundle.name(),
814-
memos=compute_memos(spend_bundle),
815-
valid_times=parse_timelock_info(extra_conditions),
804+
extra_conditions=extra_conditions,
816805
)
817806
)
818807

chia/wallet/did_wallet/did_wallet.py

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
ConditionValidTimes,
2424
CreateCoin,
2525
CreateCoinAnnouncement,
26-
parse_timelock_info,
2726
)
2827
from chia.wallet.derivation_record import DerivationRecord
2928
from chia.wallet.did_wallet import did_wallet_puzzles
@@ -44,7 +43,6 @@
4443
)
4544
from chia.wallet.transaction_record import TransactionRecord
4645
from chia.wallet.uncurried_puzzle import uncurry_puzzle
47-
from chia.wallet.util.compute_memos import compute_memos
4846
from chia.wallet.util.curry_and_treehash import NIL_TREEHASH, shatree_int, shatree_pair
4947
from chia.wallet.util.transaction_type import TransactionType
5048
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
@@ -647,25 +645,16 @@ async def create_update_spend(
647645
extra_conditions=(AssertCoinAnnouncement(asserted_id=coin_name, asserted_msg=coin_name),),
648646
)
649647
to_ph = await action_scope.get_puzzle_hash(self.wallet_state_manager, override_reuse_puzhash_with=True)
650-
did_record = TransactionRecord(
651-
confirmed_at_height=uint32(0),
652-
created_at_time=uint64(time.time()),
653-
to_puzzle_hash=to_ph,
654-
to_address=self.wallet_state_manager.encode_puzzle_hash(to_ph),
648+
did_record = self.wallet_state_manager.new_outgoing_transaction(
649+
wallet_id=self.id(),
650+
puzzle_hash=to_ph,
655651
amount=uint64(coin.amount),
656-
fee_amount=uint64(0),
657-
confirmed=False,
658-
sent=uint32(0),
652+
fee=uint64(0),
659653
spend_bundle=spend_bundle,
660654
additions=spend_bundle.additions(),
661655
removals=spend_bundle.removals(),
662-
wallet_id=self.wallet_info.id,
663-
sent_to=[],
664-
trade_id=None,
665-
type=uint32(TransactionType.OUTGOING_TX.value),
666-
name=bytes32.secret(),
667-
memos=compute_memos(spend_bundle),
668-
valid_times=parse_timelock_info(extra_conditions),
656+
name=spend_bundle.name(),
657+
extra_conditions=extra_conditions,
669658
)
670659

671660
async with action_scope.use() as interface:
@@ -733,25 +722,16 @@ async def transfer_did(
733722
extra_conditions=(AssertCoinAnnouncement(asserted_id=coin_name, asserted_msg=coin_name),),
734723
)
735724
to_ph = await action_scope.get_puzzle_hash(self.wallet_state_manager, override_reuse_puzhash_with=True)
736-
did_record = TransactionRecord(
737-
confirmed_at_height=uint32(0),
738-
created_at_time=uint64(time.time()),
739-
to_puzzle_hash=to_ph,
740-
to_address=self.wallet_state_manager.encode_puzzle_hash(to_ph),
725+
did_record = self.wallet_state_manager.new_outgoing_transaction(
726+
wallet_id=self.id(),
727+
puzzle_hash=to_ph,
741728
amount=uint64(coin.amount),
742-
fee_amount=fee,
743-
confirmed=False,
744-
sent=uint32(0),
729+
fee=fee,
745730
spend_bundle=spend_bundle,
746731
additions=spend_bundle.additions(),
747732
removals=spend_bundle.removals(),
748-
wallet_id=self.wallet_info.id,
749-
sent_to=[],
750-
trade_id=None,
751-
type=uint32(TransactionType.OUTGOING_TX.value),
752733
name=spend_bundle.name(),
753-
memos=compute_memos(spend_bundle),
754-
valid_times=parse_timelock_info(extra_conditions),
734+
extra_conditions=extra_conditions,
755735
)
756736

757737
async with action_scope.use() as interface:
@@ -813,25 +793,16 @@ async def create_message_spend(
813793
)
814794
list_of_coinspends = [make_spend(coin, full_puzzle, fullsol)]
815795
unsigned_spend_bundle = WalletSpendBundle(list_of_coinspends, G2Element())
816-
tx = TransactionRecord(
817-
confirmed_at_height=uint32(0),
818-
created_at_time=uint64(time.time()),
819-
to_puzzle_hash=p2_ph,
820-
to_address=self.wallet_state_manager.encode_puzzle_hash(p2_ph),
796+
tx = self.wallet_state_manager.new_outgoing_transaction(
797+
wallet_id=self.id(),
798+
puzzle_hash=p2_ph,
821799
amount=uint64(coin.amount),
822-
fee_amount=uint64(0),
823-
confirmed=False,
824-
sent=uint32(0),
800+
fee=uint64(0),
825801
spend_bundle=unsigned_spend_bundle,
826802
additions=unsigned_spend_bundle.additions(),
827803
removals=[coin],
828-
wallet_id=self.id(),
829-
sent_to=[],
830-
trade_id=None,
831-
type=uint32(TransactionType.OUTGOING_TX.value),
832804
name=unsigned_spend_bundle.name(),
833-
memos=compute_memos(unsigned_spend_bundle),
834-
valid_times=parse_timelock_info(extra_conditions),
805+
extra_conditions=extra_conditions,
835806
)
836807
async with action_scope.use() as interface:
837808
interface.side_effects.transactions.append(tx)

0 commit comments

Comments
 (0)