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'))
|
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'))
|
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'))
|
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)
|
old = await wallet.claims.get(claim_id=claim_id)
|
||||||
if not old.claim.is_channel:
|
if not old.claim.is_channel:
|
||||||
|
@ -1690,8 +1691,12 @@ class API:
|
||||||
amount = old.amount
|
amount = old.amount
|
||||||
|
|
||||||
tx = await wallet.channels.update(
|
tx = await wallet.channels.update(
|
||||||
old=old, amount=amount, holding_account=holding_account, funding_accounts=funding_accounts,
|
old=old, amount=amount,
|
||||||
save_key=not tx_dict['preview'], **remove_nulls(channel_edit_dict)
|
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)
|
await self.service.maybe_broadcast_or_release(tx, **tx_dict)
|
||||||
|
@ -1884,8 +1889,6 @@ class API:
|
||||||
claim_id: str, # id of the claim being reposted
|
claim_id: str, # id of the claim being reposted
|
||||||
allow_duplicate_name=False, # create new repost even if one already exists with given name
|
allow_duplicate_name=False, # create new repost even if one already exists with given name
|
||||||
account_id: str = None, # account to hold the repost
|
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
|
) -> Transaction: # transaction for the repost
|
||||||
"""
|
"""
|
||||||
|
@ -1893,38 +1896,26 @@ class API:
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
stream repost (<name> | --name=<name>) (<bid> | --bid=<bid>) (<claim_id> | --claim_id=<claim_id>)
|
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}
|
{kwargs}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
wallet = self.wallets.get_or_default(wallet_id)
|
signed_dict, kwargs = pop_kwargs('signed', extract_signed(**signed_and_tx_kwargs))
|
||||||
self.valid_stream_name_or_error(name)
|
tx_dict, kwargs = pop_kwargs('tx', extract_tx(**kwargs))
|
||||||
account = wallet.accounts.get_or_default(account_id)
|
assert_consumed_kwargs(kwargs)
|
||||||
funding_accounts = wallet.accounts.get_or_all(fund_account_id)
|
self.ledger.valid_stream_name_or_error(name)
|
||||||
channel = await self.get_channel_or_none(wallet, channel_account_id, channel_id, channel_name, for_signing=True)
|
wallet = self.wallets.get_or_default_for_spending(tx_dict.pop('wallet_id'))
|
||||||
amount = self.get_dewies_or_error('bid', bid, positive_value=True)
|
amount = self.ledger.get_dewies_or_error('bid', bid, positive_value=True)
|
||||||
claim_address = await self.get_receiving_address(claim_address, account)
|
holding_account = wallet.accounts.get_or_default(account_id)
|
||||||
claims = await account.get_claims(claim_name=name)
|
funding_accounts = wallet.accounts.get_or_all(tx_dict.pop('fund_account_id'))
|
||||||
if len(claims) > 0:
|
change_account = wallet.accounts.get_or_default(tx_dict.pop('change_account_id'))
|
||||||
if not allow_duplicate_name:
|
await wallet.verify_duplicate(name, allow_duplicate_name)
|
||||||
raise Exception(
|
tx = await wallet.streams.repost(
|
||||||
f"You already have a stream claim published under the name '{name}'. "
|
name=name, amount=amount, claim_id=claim_id,
|
||||||
f"Use --allow-duplicate-name flag to override."
|
holding_account=holding_account,
|
||||||
|
funding_accounts=funding_accounts,
|
||||||
|
change_account=change_account,
|
||||||
)
|
)
|
||||||
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
|
|
||||||
)
|
|
||||||
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)
|
await self.service.maybe_broadcast_or_release(tx, **tx_dict)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,7 @@ class IntegrationTestCase(AsyncioTestCase):
|
||||||
|
|
||||||
async def assertBalance(self, account, expected_balance: str): # pylint: disable=C0103
|
async def assertBalance(self, account, expected_balance: str): # pylint: disable=C0103
|
||||||
balance = await account.get_balance()
|
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):
|
def broadcast(self, tx):
|
||||||
return self.ledger.broadcast(tx)
|
return self.ledger.broadcast(tx)
|
||||||
|
|
|
@ -610,7 +610,7 @@ class ChannelListManager(ClaimListManager):
|
||||||
|
|
||||||
async def update(
|
async def update(
|
||||||
self, old: Output, amount: int, new_signing_key: bool, replace: bool,
|
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
|
save_key=True, **kwargs
|
||||||
) -> Transaction:
|
) -> Transaction:
|
||||||
|
|
||||||
|
@ -642,7 +642,7 @@ class ChannelListManager(ClaimListManager):
|
||||||
txo.private_key = old.private_key
|
txo.private_key = old.private_key
|
||||||
|
|
||||||
tx = await self.wallet.create_transaction(
|
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)
|
await self.wallet.sign(tx)
|
||||||
|
@ -770,6 +770,21 @@ class StreamListManager(ClaimListManager):
|
||||||
async def list(self, **constraints) -> Result[Output]:
|
async def list(self, **constraints) -> Result[Output]:
|
||||||
return await self.wallet.db.get_streams(wallet=self.wallet, **constraints)
|
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):
|
class CollectionListManager(ClaimListManager):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
|
@ -283,7 +283,7 @@ class ClaimSearchCommand(ClaimTestCase):
|
||||||
claim4 = await self.stream_create('claim4', channel_id=chan2_id)
|
claim4 = await self.stream_create('claim4', channel_id=chan2_id)
|
||||||
claim5 = await self.stream_create('claim5', channel_id=chan2_id)
|
claim5 = await self.stream_create('claim5', channel_id=chan2_id)
|
||||||
claim6 = await self.stream_create('claim6', channel_id=chan3_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
|
# {has/valid/invalid}_channel_signature
|
||||||
await match([claim6, claim5, claim4, claim3, claim2], has_channel_signature=True)
|
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()
|
address = await self.account.receiving.get_or_create_usable_address()
|
||||||
tx = await self.wallet.claims.create(
|
tx = await self.wallet.claims.create(
|
||||||
'unknown', b'{"sources":{"lbry_sd_hash":""}}', 1, address, [self.account], self.account)
|
'unknown', b'{"sources":{"lbry_sd_hash":""}}', 1, address, [self.account], self.account)
|
||||||
await self.broadcast(tx)
|
await self.service.broadcast(tx)
|
||||||
await self.confirm_tx(tx.id)
|
await self.generate(1)
|
||||||
|
await self.service.wait(tx)
|
||||||
|
|
||||||
octet = await self.stream_create()
|
octet = await self.stream_create()
|
||||||
video = await self.stream_create('chrome', file_path=self.video_file_name)
|
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=self.account.id)), 2)
|
||||||
self.assertEqual(len(await self.channel_list(account_id=account2.id)), 1)
|
self.assertEqual(len(await self.channel_list(account_id=account2.id)), 1)
|
||||||
|
|
||||||
|
@skip
|
||||||
async def test_channel_export_import_before_sending_channel(self):
|
async def test_channel_export_import_before_sending_channel(self):
|
||||||
# export
|
# export
|
||||||
tx = await self.channel_create('@foo', '1.0')
|
tx = await self.channel_create('@foo', '1.0')
|
||||||
claim_id = self.get_claim_id(tx)
|
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
|
channel_private_key = channels[0].private_key
|
||||||
exported_data = await self.out(self.api.channel_export(claim_id))
|
exported_data = await self.out(self.api.channel_export(claim_id))
|
||||||
|
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -9,9 +9,9 @@ setenv =
|
||||||
passenv =
|
passenv =
|
||||||
TEST_DB
|
TEST_DB
|
||||||
commands =
|
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.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_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}
|
#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}
|
#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}
|
#other: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.other {posargs}
|
||||||
|
|
Loading…
Add table
Reference in a new issue