Add KoreAnchor Ethereum integration - real on-chain anchoring
This commit is contained in:
@@ -16,6 +16,15 @@ import os, json, time, logging, requests, redis, psycopg2, urllib3
|
||||
from datetime import datetime, timezone
|
||||
from lick import build_headers
|
||||
|
||||
# Ethereum anchoring — import conditionally (web3 may not be installed)
|
||||
try:
|
||||
from eth_anchor import get_anchor
|
||||
ETH_ANCHOR_ENABLED = True
|
||||
except ImportError:
|
||||
ETH_ANCHOR_ENABLED = False
|
||||
import logging
|
||||
logging.getLogger(__name__).warning("eth_anchor not available — Ethereum anchoring disabled")
|
||||
|
||||
urllib3.disable_warnings()
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s [KORE-POSTER] %(levelname)s %(message)s')
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -145,6 +154,27 @@ class KoreChainPoster:
|
||||
if success:
|
||||
store_posted(self.pg, payload, 'POSTED', response_koreid)
|
||||
log.info(f"✓ {koreid} posted")
|
||||
|
||||
# Anchor to Ethereum mainnet
|
||||
if ETH_ANCHOR_ENABLED:
|
||||
try:
|
||||
anchor = get_anchor()
|
||||
tx_hash = anchor.anchor(
|
||||
kore_id=koreid,
|
||||
uetr=payload.get('uetr', ''),
|
||||
event_type=payload.get('step', 'ANCHOR'),
|
||||
amount=float(payload.get('amount', 0)),
|
||||
currency=payload.get('currency', 'USD'),
|
||||
linked_to=payload.get('linked_to', 'GENESIS-07'),
|
||||
payload=payload,
|
||||
)
|
||||
if tx_hash and tx_hash != 'already_anchored':
|
||||
log.info(f"⛓ Ethereum anchor tx: {tx_hash}")
|
||||
store_posted(self.pg, {**payload, 'ethereum_tx': tx_hash}, 'ETH_ANCHORED', tx_hash)
|
||||
elif tx_hash == 'already_anchored':
|
||||
log.info(f"⛓ Already on Ethereum: {koreid}")
|
||||
except Exception as e:
|
||||
log.error(f"Ethereum anchor error for {koreid}: {e}")
|
||||
else:
|
||||
retries += 1
|
||||
if retries < MAX_RETRIES:
|
||||
|
||||
Reference in New Issue
Block a user