Fix bulk tx (#14372)

* Add NFT bulk transfer API

* Fix pre-commit

* Improve unit test

* Fix precommit

* Improve unit test

* Fix response json serialization

* Fix bulk API missing transaction

* Remove print
This commit is contained in:
Kronus91 2023-01-20 10:02:17 -08:00 committed by GitHub
parent 7bdf7dc478
commit ad51c3c251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 8 deletions

View File

@ -2268,7 +2268,7 @@ class WalletRpcApi:
for tx in tx_list:
if tx.spend_bundle is not None:
spend_bundles.append(tx.spend_bundle)
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
if len(spend_bundles) > 0:
spend_bundle = SpendBundle.aggregate(spend_bundles)
@ -2281,7 +2281,12 @@ class WalletRpcApi:
await nft_wallet.update_coin_status(coin, True)
for wallet_id in nft_dict.keys():
self.service.wallet_state_manager.state_changed("nft_coin_did_set", wallet_id)
return {"wallet_id": list(nft_dict.keys()), "success": True, "spend_bundle": spend_bundle}
return {
"wallet_id": list(nft_dict.keys()),
"success": True,
"spend_bundle": spend_bundle,
"tx_num": len(refined_tx_list),
}
else:
raise ValueError("Couldn't set DID on given NFT")
@ -2342,7 +2347,7 @@ class WalletRpcApi:
for tx in tx_list:
if tx.spend_bundle is not None:
spend_bundles.append(tx.spend_bundle)
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
if len(spend_bundles) > 0:
spend_bundle = SpendBundle.aggregate(spend_bundles)
@ -2354,7 +2359,12 @@ class WalletRpcApi:
await nft_wallet.update_coin_status(coin, True)
for wallet_id in nft_dict.keys():
self.service.wallet_state_manager.state_changed("nft_coin_did_set", wallet_id)
return {"wallet_id": list(nft_dict.keys()), "success": True, "spend_bundle": spend_bundle}
return {
"wallet_id": list(nft_dict.keys()),
"success": True,
"spend_bundle": spend_bundle,
"tx_num": len(refined_tx_list),
}
else:
raise ValueError("Couldn't transfer given NFTs")

View File

@ -1092,7 +1092,7 @@ class NFTWallet:
for tx in nft_tx_record:
if tx.spend_bundle is not None:
spend_bundles.append(tx.spend_bundle)
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
if len(spend_bundles) > 0:
spend_bundle = SpendBundle.aggregate(spend_bundles)
@ -1129,7 +1129,7 @@ class NFTWallet:
for tx in nft_tx_record:
if tx.spend_bundle is not None:
spend_bundles.append(tx.spend_bundle)
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
refined_tx_list.append(dataclasses.replace(tx, spend_bundle=None))
if len(spend_bundles) > 0:
spend_bundle = SpendBundle.aggregate(spend_bundles)

View File

@ -1284,7 +1284,9 @@ async def test_nft_bulk_set_did(self_hostname: str, two_wallet_nodes: Any, trust
{"wallet_id": nft_wallet_1_id},
{"nft_coin_id": nft2.nft_coin_id.hex()},
]
resp = await api_0.nft_set_did_bulk(dict(did_id=hmr_did_id, nft_coin_list=nft_coin_list))
resp = await api_0.nft_set_did_bulk(dict(did_id=hmr_did_id, nft_coin_list=nft_coin_list, fee=1000))
assert len(resp["spend_bundle"].coin_spends) == 4
assert resp["tx_num"] == 3
coins_response = await wait_rpc_state_condition(
30, api_0.nft_get_nfts, [{"wallet_id": nft_wallet_0_id}], lambda x: len(x["nft_list"]) == 1
)
@ -1427,7 +1429,9 @@ async def test_nft_bulk_transfer(two_wallet_nodes: Any, trusted: Any) -> None:
{"wallet_id": nft_wallet_1_id},
{"nft_coin_id": nft2.nft_coin_id.hex()},
]
resp = await api_0.nft_transfer_bulk(dict(target_address=address, nft_coin_list=nft_coin_list))
resp = await api_0.nft_transfer_bulk(dict(target_address=address, nft_coin_list=nft_coin_list, fee=1000))
assert len(resp["spend_bundle"].coin_spends) == 3
assert resp["tx_num"] == 3
sb = await make_new_block_with(resp, full_node_api, ph)
# ensure hints are generated
assert compute_memos(sb)