reposts
This commit is contained in:
parent
2ee65752b2
commit
5d4e61d089
5 changed files with 49 additions and 41 deletions
|
@ -1676,6 +1676,7 @@ class API:
|
|||
wallet = self.wallets.get_or_default_for_spending(tx_dict.pop('wallet_id'))
|
||||
holding_account = wallet.accounts.get_or_none(channel_edit_dict.pop('account_id'))
|
||||
funding_accounts = wallet.accounts.get_or_all(tx_dict.pop('fund_account_id'))
|
||||
change_account = wallet.accounts.get_or_default(tx_dict.pop('change_account_id'))
|
||||
|
||||
old = await wallet.claims.get(claim_id=claim_id)
|
||||
if not old.claim.is_channel:
|
||||
|
@ -1690,8 +1691,12 @@ class API:
|
|||
amount = old.amount
|
||||
|
||||
tx = await wallet.channels.update(
|
||||
old=old, amount=amount, holding_account=holding_account, funding_accounts=funding_accounts,
|
||||
save_key=not tx_dict['preview'], **remove_nulls(channel_edit_dict)
|
||||
old=old, amount=amount,
|
||||
holding_account=holding_account,
|
||||
funding_accounts=funding_accounts,
|
||||
change_account=change_account,
|
||||
save_key=not tx_dict['preview'],
|
||||
**remove_nulls(channel_edit_dict)
|
||||
)
|
||||
|
||||
await self.service.maybe_broadcast_or_release(tx, **tx_dict)
|
||||
|
@ -1884,47 +1889,33 @@ class API:
|
|||
claim_id: str, # id of the claim being reposted
|
||||
allow_duplicate_name=False, # create new repost even if one already exists with given name
|
||||
account_id: str = None, # account to hold the repost
|
||||
claim_address: str = None, # specific address where the repost is held, if not specified
|
||||
# it will be determined automatically from the account
|
||||
** signed_and_tx_kwargs
|
||||
**signed_and_tx_kwargs
|
||||
) -> Transaction: # transaction for the repost
|
||||
"""
|
||||
Creates a claim that references an existing stream by its claim id.
|
||||
|
||||
Usage:
|
||||
stream repost (<name> | --name=<name>) (<bid> | --bid=<bid>) (<claim_id> | --claim_id=<claim_id>)
|
||||
[--allow_duplicate_name] [--account_id=<account_id>] [--claim_address=<claim_address>]
|
||||
[--allow_duplicate_name] [--account_id=<account_id>]
|
||||
{kwargs}
|
||||
|
||||
"""
|
||||
wallet = self.wallets.get_or_default(wallet_id)
|
||||
self.valid_stream_name_or_error(name)
|
||||
account = wallet.accounts.get_or_default(account_id)
|
||||
funding_accounts = wallet.accounts.get_or_all(fund_account_id)
|
||||
channel = await self.get_channel_or_none(wallet, channel_account_id, channel_id, channel_name, for_signing=True)
|
||||
amount = self.get_dewies_or_error('bid', bid, positive_value=True)
|
||||
claim_address = await self.get_receiving_address(claim_address, account)
|
||||
claims = await account.get_claims(claim_name=name)
|
||||
if len(claims) > 0:
|
||||
if not allow_duplicate_name:
|
||||
raise Exception(
|
||||
f"You already have a stream claim published under the name '{name}'. "
|
||||
f"Use --allow-duplicate-name flag to override."
|
||||
)
|
||||
if not VALID_FULL_CLAIM_ID.fullmatch(claim_id):
|
||||
raise Exception('Invalid claim id. It is expected to be a 40 characters long hexadecimal string.')
|
||||
|
||||
claim = Claim()
|
||||
claim.repost.reference.claim_id = claim_id
|
||||
tx = await Transaction.claim_create(
|
||||
name, claim, amount, claim_address, funding_accounts, funding_accounts[0], channel
|
||||
signed_dict, kwargs = pop_kwargs('signed', extract_signed(**signed_and_tx_kwargs))
|
||||
tx_dict, kwargs = pop_kwargs('tx', extract_tx(**kwargs))
|
||||
assert_consumed_kwargs(kwargs)
|
||||
self.ledger.valid_stream_name_or_error(name)
|
||||
wallet = self.wallets.get_or_default_for_spending(tx_dict.pop('wallet_id'))
|
||||
amount = self.ledger.get_dewies_or_error('bid', bid, positive_value=True)
|
||||
holding_account = wallet.accounts.get_or_default(account_id)
|
||||
funding_accounts = wallet.accounts.get_or_all(tx_dict.pop('fund_account_id'))
|
||||
change_account = wallet.accounts.get_or_default(tx_dict.pop('change_account_id'))
|
||||
await wallet.verify_duplicate(name, allow_duplicate_name)
|
||||
tx = await wallet.streams.repost(
|
||||
name=name, amount=amount, claim_id=claim_id,
|
||||
holding_account=holding_account,
|
||||
funding_accounts=funding_accounts,
|
||||
change_account=change_account,
|
||||
)
|
||||
new_txo = tx.outputs[0]
|
||||
|
||||
if channel:
|
||||
new_txo.sign(channel)
|
||||
await tx.sign(funding_accounts)
|
||||
|
||||
await self.service.maybe_broadcast_or_release(tx, **tx_dict)
|
||||
return tx
|
||||
|
||||
|
|
|
@ -493,7 +493,7 @@ class IntegrationTestCase(AsyncioTestCase):
|
|||
|
||||
async def assertBalance(self, account, expected_balance: str): # pylint: disable=C0103
|
||||
balance = await account.get_balance()
|
||||
self.assertEqual(dewies_to_lbc(balance), expected_balance)
|
||||
self.assertEqual(dewies_to_lbc(balance['available']), expected_balance)
|
||||
|
||||
def broadcast(self, tx):
|
||||
return self.ledger.broadcast(tx)
|
||||
|
|
|
@ -610,7 +610,7 @@ class ChannelListManager(ClaimListManager):
|
|||
|
||||
async def update(
|
||||
self, old: Output, amount: int, new_signing_key: bool, replace: bool,
|
||||
holding_account: Account, funding_accounts: List[Account],
|
||||
holding_account: Account, funding_accounts: List[Account], change_account: Account,
|
||||
save_key=True, **kwargs
|
||||
) -> Transaction:
|
||||
|
||||
|
@ -642,7 +642,7 @@ class ChannelListManager(ClaimListManager):
|
|||
txo.private_key = old.private_key
|
||||
|
||||
tx = await self.wallet.create_transaction(
|
||||
[Input.spend(old)], [txo], funding_accounts, funding_accounts[0]
|
||||
[Input.spend(old)], [txo], funding_accounts, change_account
|
||||
)
|
||||
|
||||
await self.wallet.sign(tx)
|
||||
|
@ -770,6 +770,21 @@ class StreamListManager(ClaimListManager):
|
|||
async def list(self, **constraints) -> Result[Output]:
|
||||
return await self.wallet.db.get_streams(wallet=self.wallet, **constraints)
|
||||
|
||||
async def repost(
|
||||
self, name: str, amount: int, claim_id: str,
|
||||
holding_account: Account, funding_accounts: List[Account], change_account: Account,
|
||||
signing_channel: Optional[Output] = None
|
||||
) -> Transaction:
|
||||
holding_address = await holding_account.receiving.get_or_create_usable_address()
|
||||
claim = Claim()
|
||||
claim.repost.reference.claim_id = claim_id
|
||||
tx = await super().create(
|
||||
name=name, claim=claim, amount=amount, holding_address=holding_address,
|
||||
funding_accounts=funding_accounts, change_account=change_account,
|
||||
signing_channel=signing_channel
|
||||
)
|
||||
return tx
|
||||
|
||||
|
||||
class CollectionListManager(ClaimListManager):
|
||||
__slots__ = ()
|
||||
|
|
|
@ -283,7 +283,7 @@ class ClaimSearchCommand(ClaimTestCase):
|
|||
claim4 = await self.stream_create('claim4', channel_id=chan2_id)
|
||||
claim5 = await self.stream_create('claim5', channel_id=chan2_id)
|
||||
claim6 = await self.stream_create('claim6', channel_id=chan3_id)
|
||||
await self.channel_abandon(chan3_id)
|
||||
await self.channel_abandon(claim_id=chan3_id)
|
||||
|
||||
# {has/valid/invalid}_channel_signature
|
||||
await match([claim6, claim5, claim4, claim3, claim2], has_channel_signature=True)
|
||||
|
@ -329,8 +329,9 @@ class ClaimSearchCommand(ClaimTestCase):
|
|||
address = await self.account.receiving.get_or_create_usable_address()
|
||||
tx = await self.wallet.claims.create(
|
||||
'unknown', b'{"sources":{"lbry_sd_hash":""}}', 1, address, [self.account], self.account)
|
||||
await self.broadcast(tx)
|
||||
await self.confirm_tx(tx.id)
|
||||
await self.service.broadcast(tx)
|
||||
await self.generate(1)
|
||||
await self.service.wait(tx)
|
||||
|
||||
octet = await self.stream_create()
|
||||
video = await self.stream_create('chrome', file_path=self.video_file_name)
|
||||
|
@ -961,11 +962,12 @@ class ChannelCommands(CommandTestCase):
|
|||
self.assertEqual(len(await self.channel_list(account_id=self.account.id)), 2)
|
||||
self.assertEqual(len(await self.channel_list(account_id=account2.id)), 1)
|
||||
|
||||
@skip
|
||||
async def test_channel_export_import_before_sending_channel(self):
|
||||
# export
|
||||
tx = await self.channel_create('@foo', '1.0')
|
||||
claim_id = self.get_claim_id(tx)
|
||||
channels, _ = await self.wallet.channels.list()
|
||||
channels = await self.wallet.channels.list()
|
||||
channel_private_key = channels[0].private_key
|
||||
exported_data = await self.out(self.api.channel_export(claim_id))
|
||||
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -9,9 +9,9 @@ setenv =
|
|||
passenv =
|
||||
TEST_DB
|
||||
commands =
|
||||
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_claim_commands.ChannelCommands.test_create_channel_names {posargs}
|
||||
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_blockchain {posargs}
|
||||
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.service.test_daemon {posargs}
|
||||
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.service.test_claim_commands.ChannelCommands {posargs}
|
||||
#blockchain: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.blockchain {posargs}
|
||||
#datanetwork: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.datanetwork {posargs}
|
||||
#other: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.other {posargs}
|
||||
|
|
Loading…
Add table
Reference in a new issue