Exemple #1
0
    def checkBlock(self, heightToCheck):
        #check content of the block for valid transactions
        block = self.tnc.getBlock(heightToCheck)
        for transaction in block['transactions']:
            targetAddress = self.tnc.checkTx(transaction)

            if targetAddress is not None:
                if targetAddress != "No attachment":
                    if not(otherCalls(self.config, self.db).validateaddress(targetAddress)):
                        self.faultHandler(transaction, "txerror")
                    else:
                        targetAddress = otherCalls(self.config, self.db).normalizeAddress(targetAddress)
                        amount = transaction['amount'] / pow(10, self.config['tn']['decimals'])
                        amount = round(amount, 8)
                        
                        if amount < self.config['main']['min'] or amount > self.config['main']['max']:
                            self.faultHandler(transaction, "senderror", e='outside amount ranges')
                        else:
                            try:
                                txId = None
                                self.db.insTunnel('sending', transaction['sender'], targetAddress)
                                txId = otherCalls(self.config, self.db).sendTx(targetAddress, amount)

                                if 'error' in txId:
                                    self.faultHandler(transaction, "senderror", e=txId)
                                    self.db.updTunnel("error", transaction['sender'], targetAddress, statusOld="sending")
                                else:
                                    print("INFO: send tx: " + str(txId))

                                    self.db.insExecuted(transaction['sender'], targetAddress, txId, transaction['id'], amount, self.config['other']['fee'])
                                    print('INFO: send tokens from tn to other!')

                                    #self.db.delTunnel(transaction['sender'], targetAddress)
                                    self.db.updTunnel("verifying", transaction['sender'], targetAddress, statusOld='sending')
                            except Exception as e:
                                self.faultHandler(transaction, "txerror", e=e)
                                continue

                            if txId is None:
                                if targetAddress != 'invalid address':
                                    self.db.insError(transaction['sender'], targetAddress, transaction['id'], '', amount, 'tx failed to send - manual intervention required')
                                    print("ERROR: tx failed to send - manual intervention required")
                                    self.db.updTunnel("error", transaction['sender'], targetAddress, statusOld="sending")
                            else:
                                otherCalls(self.config, self.db).verifyTx(txId, transaction['sender'], targetAddress)
                else:
                    self.faultHandler(transaction, 'noattachment')
Exemple #2
0
def initialisedb(db):
    #get current TN block:
    tnlatestBlock = tnCalls(config).currentBlock()
    db.insHeights(tnlatestBlock, 'TN')

    #get current ETH block:
    ethlatestBlock = otherCalls(config).currentBlock()
    db.insHeights(ethlatestBlock, 'ETH')
    def __init__(self, config, db=None):
        self.config = config

        if db == None:
            if self.config['main']['use-pg']:
                self.db = dbPGCalls(config)
            else:
                self.db = dbCalls(config)
        else:
            self.db = db

        self.tnc = tnCalls(config, self.db)
        self.otc = otherCalls(config, self.db)
    def __init__(self, config):
        self.config = config
        self.otc = otherCalls(config)

        if self.config['main']['use-pg']:
            self.db = dbPGCalls(config)
        else:
            self.db = dbCalls(config)

        self.apikey = self.config['other']['etherscan-apikey']
        self.url = 'https://api.etherscan.io/api?'

        self.lastScannedBlock = self.db.lastScannedBlock("ETH")
Exemple #5
0
    def __init__(self, config):
        self.config = config
        self.tnc = tnCalls(config)

        if self.config['main']['use-pg']:
            self.db = dbPGCalls(config)
        else:
            self.db = dbCalls(config)

        if self.config['other']['etherscan-on']:
            self.otc = etherscanCalls(config)
        else:
            self.otc = otherCalls(config)
def initialisedb():
    #get current TN block:
    tnlatestBlock = tnCalls(config).currentBlock()
    if config['main']['use-pg']:
        dbPGCalls(config).insHeights(tnlatestBlock, 'TN')
    else:
        dbCalls(config).insHeights(tnlatestBlock, 'TN')

    #get current ETH block:
    ethlatestBlock = otherCalls(config).currentBlock()
    if config['main']['use-pg']:
        dbPGCalls(config).insHeights(ethlatestBlock, 'ETH')
    else:
        dbCalls(config).insHeights(ethlatestBlock, 'ETH')
    def __init__(self, config, db=None):
        self.config = config

        if db == None:
            if self.config['main']['use-pg']:
                self.db = dbPGCalls(config)
            else:
                self.db = dbCalls(config)
        else:
            self.db = db

        self.tnc = tnCalls(config, self.db)
        self.verifier = verifier(config, self.db)
        self.otc = otherCalls(config, self.db)

        self.lastScannedBlock = self.db.lastScannedBlock("Other")
Exemple #8
0
    def __init__(self, config):
        self.config = config
        self.tnc = tnCalls(config)
        self.verifier = verifier(config)

        if self.config['other']['etherscan-on']:
            self.otc = etherscanCalls(config)
        else:
            self.otc = otherCalls(config)

        if self.config['main']['use-pg']:
            self.db = dbPGCalls(config)
        else:
            self.db = dbCalls(config)

        self.lastScannedBlock = self.db.lastScannedBlock("ETH")
Exemple #9
0
    def __init__(self, config, db=None):
        self.config = config

        if db == None:
            if self.config['main']['use-pg']:
                self.db = dbPGCalls(config)
            else:
                self.db = dbCalls(config)
        else:
            self.db = db

        self.tnc = tnCalls(config, self.db)
        self.verifier = verifier(config, self.db)

        if self.config['other']['etherscan-on']:
            self.otc = etherscanCalls(config, self.db)
        else:
            self.otc = otherCalls(config, self.db)
Exemple #10
0
async def createTunnel(targetAddress: str):
    targetAddress = re.sub('[\W_]+', '', targetAddress)

    if not tnCalls(config, dbc).validateaddress(targetAddress):
        return cExecResult(successful=0, address='')

    if targetAddress == config['tn']['gatewayAddress']:
        return {'successful': '0'}

    result = dbc.getSourceAddress(targetAddress)
    if len(result) == 0:
        sourceAddress = otherCalls(config, dbc).getNewAddress()

        dbc.insTunnel("created", sourceAddress, targetAddress)
        print("INFO: tunnel created")
        return cExecResult(successful=1, address=sourceAddress)
    else:
        return cExecResult(successful=2, address=result[0][0])
templates = Jinja2Templates(directory="templates")

with open('config.json') as json_file:
    config = json.load(json_file)

if config['main']['use-pg']:
    dbc = dbPGCalls(config)
else:
    dbc = dbCalls(config)

tnc = tnCalls(config, dbc)

if config['other']['etherscan-on']:
    otc = etherscanCalls(config, dbc)
else:
    otc = otherCalls(config, dbc)

checkit = verifier(config, dbc)


def get_current_username(
        credentials: HTTPBasicCredentials = Depends(security)):
    correct_username = secrets.compare_digest(credentials.username,
                                              config["main"]["admin-username"])
    correct_password = secrets.compare_digest(credentials.password,
                                              config["main"]["admin-password"])
    if not (correct_username and correct_password):
        print("ERROR: invalid logon details")
        raise HTTPException(
            status_code=HTTP_401_UNAUTHORIZED,
            detail="Incorrect email or password",
    allow_headers=["*"],
)

security = HTTPBasic()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")

with open('config.json') as json_file:
    config = json.load(json_file)

tnc = tnCalls(config)

if config['other']['etherscan-on']:
    otc = etherscanCalls(config)
else:
    otc = otherCalls(config)

if config['main']['use-pg']:
    dbc = dbPGCalls(config)
else:
    dbc = dbCalls(config)

checkit = verifier(config)


def get_current_username(
        credentials: HTTPBasicCredentials = Depends(security)):
    correct_username = secrets.compare_digest(credentials.username,
                                              config["main"]["admin-username"])
    correct_password = secrets.compare_digest(credentials.password,
                                              config["main"]["admin-password"])
Exemple #13
0
def get_otherBalance():
    return otherCalls(config, dbc).currentBalance()