Include payment info in deployment record.

This commit is contained in:
Thomas E Lackey 2024-08-16 22:33:23 -05:00
parent 07030044ec
commit b449d88b6c
2 changed files with 32 additions and 6 deletions

View File

@ -55,6 +55,7 @@ def process_app_deployment_request(
force_rebuild, force_rebuild,
fqdn_policy, fqdn_policy,
recreate_on_deploy, recreate_on_deploy,
payment_address,
logger, logger,
): ):
logger.log("BEGIN - process_app_deployment_request") logger.log("BEGIN - process_app_deployment_request")
@ -226,6 +227,7 @@ def process_app_deployment_request(
dns_lrn, dns_lrn,
deployment_dir, deployment_dir,
app_deployment_request, app_deployment_request,
payment_address,
logger, logger,
) )
logger.log("Publication complete.") logger.log("Publication complete.")
@ -482,11 +484,17 @@ def command( # noqa: C901
# Find deployments. # Find deployments.
main_logger.log("Discovering existing app deployments...") main_logger.log("Discovering existing app deployments...")
if all_requests:
deployments = laconic.app_deployments() deployments = laconic.app_deployments()
else:
deployments = laconic.app_deployments({"by": payment_address})
deployments_by_request = {} deployments_by_request = {}
deployments_by_payment = {}
for d in deployments: for d in deployments:
if d.attributes.request: if d.attributes.request:
deployments_by_request[d.attributes.request] = d deployments_by_request[d.attributes.request] = d
if d.attributes.payment:
deployments_by_request[d.attributes.payment] = d
# Find removal requests. # Find removal requests.
main_logger.log("Discovering deployment removal and cancellation requests...") main_logger.log("Discovering deployment removal and cancellation requests...")
@ -524,7 +532,13 @@ def command( # noqa: C901
if min_required_payment: if min_required_payment:
for r in requests_to_check_for_payment: for r in requests_to_check_for_payment:
main_logger.log(f"{r.id}: Confirming payment...") main_logger.log(f"{r.id}: Confirming payment...")
if confirm_payment( if r.attributes.payment in deployments_by_payment:
main_logger.log(
f"Skipping request {r.id}: payment already applied to deployment "
f"{deployments_by_payment[r.attributes.payment].id}"
)
dump_known_requests(state_file, [r], status="UNPAID")
elif confirm_payment(
laconic, r, payment_address, min_required_payment, main_logger laconic, r, payment_address, min_required_payment, main_logger
): ):
main_logger.log(f"{r.id}: Payment confirmed.") main_logger.log(f"{r.id}: Payment confirmed.")
@ -578,6 +592,7 @@ def command( # noqa: C901
force_rebuild, force_rebuild,
fqdn_policy, fqdn_policy,
recreate_on_deploy, recreate_on_deploy,
payment_address,
build_logger, build_logger,
) )
status = "DEPLOYED" status = "DEPLOYED"

View File

@ -96,7 +96,7 @@ def is_id(name_or_id: str):
def confirm_payment(laconic, record, payment_address, min_amount, logger): def confirm_payment(laconic, record, payment_address, min_amount, logger):
if not record.attributes.payment: if not record.attributes.payment:
logger.log(f"{record.id}: not payment tx") logger.log(f"{record.id}: no payment tx info")
return False return False
tx = laconic.get_tx(record.attributes.payment) tx = laconic.get_tx(record.attributes.payment)
@ -147,10 +147,13 @@ class LaconicRegistryClient:
return None return None
def get_owner(self, record): def get_owner(self, record, require=False):
bond = self.get_bond(record.bondId, require=True) bond = self.get_bond(record.bondId, require)
if bond:
return bond.owner return bond.owner
return bond
def get_account(self, address, refresh=False, require=False): def get_account(self, address, refresh=False, require=False):
if not refresh and address in self.cache["accounts"]: if not refresh and address in self.cache["accounts"]:
return self.cache["accounts"][address] return self.cache["accounts"][address]
@ -563,6 +566,7 @@ def publish_deployment(
dns_lrn, dns_lrn,
deployment_dir, deployment_dir,
app_deployment_request=None, app_deployment_request=None,
payment_address=None,
logger=None, logger=None,
): ):
if not deploy_record: if not deploy_record:
@ -614,6 +618,13 @@ def publish_deployment(
} }
if app_deployment_request: if app_deployment_request:
new_deployment_record["record"]["request"] = app_deployment_request.id new_deployment_record["record"]["request"] = app_deployment_request.id
if app_deployment_request.attributes.payment:
new_deployment_record["record"][
"payment"
] = app_deployment_request.attributes.payment
if payment_address:
new_deployment_record["record"]["by"] = payment_address
if logger: if logger:
logger.log("Publishing ApplicationDeploymentRecord.") logger.log("Publishing ApplicationDeploymentRecord.")