def process_operations(self, operations) :
        for operation in operations[::-1] :
            opID         = operation["id"]
            block        = operation["block_num"]
            op           = operation["op"][1]

            # Get assets involved in Fee and Transfer
            fee_asset    = api.getObject(op["fee"]["asset_id"])
            amount_asset = api.getObject(op["amount"]["asset_id"])

            # Amounts for fee and transfer
            fee_amount   =    op["fee"]["amount"] / float(10**int(fee_asset["precision"]))
            amount_amount= op["amount"]["amount"] / float(10**int(amount_asset["precision"]))

            # Get accounts involved
            from_account = api.getObject(op["from"])
            to_account   = api.getObject(op["to"])

            # Decode the memo
            memo         = op["memo"]
            try : # if possible
                privkey = PrivateKey(memo_wif_key)
                pubkey  = PublicKey(memo["from"], prefix=prefix)
                memomsg = Memo.decode_memo(privkey, pubkey, memo["nonce"], memo["message"])
            except Exception as e: # if not possible
                memomsg = "--cannot decode-- (%s)" % str(e)

            # Print out
            print("last_op: %s | block:%s | from %s -> to: %s | fee: %f %s | amount: %f %s | memo: %s" % (
                      opID, block, 
                      from_account["name"], to_account["name"],
                      fee_amount, fee_asset["symbol"],
                      amount_amount, amount_asset["symbol"],
                      memomsg))
Exemple #2
0
    def process_operations(self, operations) :
        for operation in operations[::-1] :
            opID         = operation["id"]
            block        = operation["block_num"]
            op           = operation["op"][1]

            if not "amount" in op:
                continue

            # Get assets involved in Fee and Transfer
            fee_asset    = api.getObject(op["fee"]["asset_id"])
            amount_asset = api.getObject(op["amount"]["asset_id"])

            # Amounts for fee and transfer
            fee_amount   =    float(op["fee"]["amount"]) / float(10**int(fee_asset["precision"]))
            amount_amount= float(op["amount"]["amount"]) / float(10**int(amount_asset["precision"]))

            # Get accounts involved
            from_account = api.getObject(op["from"])
            to_account   = api.getObject(op["to"])

            # Decode the memo
            memo         = op["memo"]
            try : # if possible
                privkey = PrivateKey(config.memo_wif_key)
                pubkey  = PublicKey(memo["from"], prefix=prefix)
                memomsg = Memo.decode_memo(privkey, pubkey, memo["nonce"], memo["message"])
            except Exception as e: # if not possible
                print("--cannot decode-- %s" % e)
                continue

            # Print out
            print("last_op: %s | block:%s | from %s -> to: %s | fee: %f %s | amount: %f %s | memo: %s" % (
                      opID, block, 
                      from_account["name"], to_account["name"],
                      fee_amount, fee_asset["symbol"],
                      amount_amount, amount_asset["symbol"],
                      memomsg))

            # Parse the memo
            pattern       = re.compile('[A-Z0-9]{3}-[A-Z0-9-]{8}')
            searchResults = pattern.search(memomsg)
            if not searchResults:
                continue
            ref_code      = searchResults.group(0)

            email = ""    
            pattern       = re.compile('[a-z0-9][-a-z0-9_\+\.]*[a-z0-9]\@.+\.[a-z]+')
            searchResults = pattern.search(memomsg.lower())
            if searchResults:
                email      = searchResults.group(0)

            # Request to Faucet
            headers  = {'content-type': 'text/plain'}
            query = "refcode[code]=%s&refcode[account]=%s&refcode[asset_symbol]=%s&refcode[asset_amount]=%s&refcode[send_to]=%s" % (ref_code, from_account["name"], amount_asset["symbol"], op["amount"]["amount"], email)
            print("--- query: %s" % query)
            response = requests.post(config.faucet_url,
                                     params=query,
                                     headers=headers)
Exemple #3
0
    def process_operations(self, operations) :
        for operation in operations[::-1] :
            opID         = operation["id"]
            block        = operation["block_num"]
            op           = operation["op"][1]

            if operation["op"][0] != 0 :
                continue

            " Get assets involved in Fee and Transfer "
            fee_asset    = graphene.getObject(op["fee"]["asset_id"])
            amount_asset = graphene.getObject(op["amount"]["asset_id"])

            " Amounts for fee and transfer "
            fee_amount    = float(op["fee"]["amount"]) / float(
                10 ** int(fee_asset["precision"]))
            amount_amount = float(op["amount"]["amount"]) / float(
                10 ** int(amount_asset["precision"]))

            " Get accounts involved "
            from_account = graphene.getObject(op["from"])
            to_account   = graphene.getObject(op["to"])

            " Decode the memo "
            memomsg = ""
            if "memo" in op :
                memo         = op["memo"]
                try :
                    account_name = to_account["name"]
                    if account_name not in self.memo_wif_keys:
                        memomsg = "-- missing wif key for %s" % account_name
                    else :
                        privkey = PrivateKey(self.memo_wif_keys[account_name])
                        pubkey  = PublicKey(memo["from"], prefix=self.prefix)
                        memomsg = Memo.decode_memo(privkey, pubkey,
                                                   memo["nonce"],
                                                   memo["message"])
                except Exception as e:
                    memomsg = "--cannot decode-- (%s)" % str(e)

            " Print out "
            print(("last_op: %s | block:%s | from %s -> to: %s " +
                  "| fee: %f %s | amount: %f %s | memo: %s") % (
                      opID, block,
                      from_account["name"], to_account["name"],
                      fee_amount, fee_asset["symbol"],
                      amount_amount, amount_asset["symbol"],
                      memomsg))

            " Store this as last op seen"
            self.last_op = opID
    def process_operations(self, op_id):
        op_info = self.node_api.get_objects([op_id])
        for operation in op_info[::-1]:
            if operation["op"][0] != 0:
                return
            op = operation["op"][1]
            trx = {}

            # trx["timestamp"] = datetime.datetime.utcnow().strftime(
            #     "%Y%m%d %H:%M")
            trx["block_num"] = operation["block_num"]
            block_info = self.node_api.get_block(trx["block_num"])
            trx["timestamp"] = block_info["timestamp"]
            trx["trx_id"] = operation["id"]
            # Get amount
            asset_info = self.get_asset_info(op["amount"]["asset_id"])
            trx["asset"] = asset_info["symbol"]
            trx["amount"] = float(op["amount"]["amount"]) / float(10**int(
                asset_info["precision"]))

            # Get accounts involved
            trx["from_id"] = op["from"]
            trx["to_id"] = op["to"]
            trx["from"] = self.node_api.get_objects([op["from"]])[0]["name"]
            trx["to"] = self.node_api.get_objects([op["to"]])[0]["name"]

            # Decode the memo
            if "memo" in op:
                memo = op["memo"]
                trx["nonce"] = memo["nonce"]
                try:
                    privkey = PrivateKey(self.memo_key)
                    if trx["to_id"] == self.account["id"]:
                        pubkey = PublicKey(memo["from"], prefix=self.prefix)
                    else:
                        pubkey = PublicKey(memo["to"], prefix=self.prefix)
                    trx["memo"] = Memo.decode_memo(privkey, pubkey,
                                                   memo["nonce"],
                                                   memo["message"])
                except Exception:
                    trx["memo"] = None
            else:
                trx["nonce"] = None
                trx["memo"] = None

            if trx["from_id"] == self.account["id"]:
                self.onSent(trx)
            elif trx["to_id"] == self.account["id"]:
                self.onReceive(trx)
Exemple #5
0
    def process_operations(self, operations):
        for operation in operations[::-1]:
            opID = operation["id"]
            block = operation["block_num"]
            op = operation["op"][1]

            if operation["op"][0] != 0:
                continue

            " Get assets involved in Fee and Transfer "
            fee_asset = graphene.getObject(op["fee"]["asset_id"])
            amount_asset = graphene.getObject(op["amount"]["asset_id"])

            " Amounts for fee and transfer "
            fee_amount = float(op["fee"]["amount"]) / float(10**int(
                fee_asset["precision"]))
            amount_amount = float(op["amount"]["amount"]) / float(10**int(
                amount_asset["precision"]))

            " Get accounts involved "
            from_account = graphene.getObject(op["from"])
            to_account = graphene.getObject(op["to"])

            " Decode the memo "
            memomsg = ""
            if "memo" in op:
                memo = op["memo"]
                try:
                    account_name = to_account["name"]
                    if account_name not in self.memo_wif_keys:
                        memomsg = "-- missing wif key for %s" % account_name
                    else:
                        privkey = PrivateKey(self.memo_wif_keys[account_name])
                        pubkey = PublicKey(memo["from"], prefix=self.prefix)
                        memomsg = Memo.decode_memo(privkey, pubkey,
                                                   memo["nonce"],
                                                   memo["message"])
                except Exception as e:
                    memomsg = "--cannot decode-- (%s)" % str(e)

            " Print out "
            print(("last_op: %s | block:%s | from %s -> to: %s " +
                   "| fee: %f %s | amount: %f %s | memo: %s") %
                  (opID, block, from_account["name"], to_account["name"],
                   fee_amount, fee_asset["symbol"], amount_amount,
                   amount_asset["symbol"], memomsg))

            " Store this as last op seen"
            self.last_op = opID
Exemple #6
0
    def process_operations(self, operations) :
        for operation in operations[::-1] :
            opID         = operation["id"]
            block        = operation["block_num"]
            op           = operation["op"][1]

            " Consider only Transfer operations "
            if operation["op"][0] != 0:
                continue

            # Get assets involved in Fee and Transfer
            fee_asset    = api.getObject(op["fee"]["asset_id"])
            amount_asset = api.getObject(op["amount"]["asset_id"])

            # Amounts for fee and transfer
            fee_amount = float(op["fee"]["amount"]) / float(10 ** int(fee_asset["precision"]))
            amount_amount = float(op["amount"]["amount"]) / float(10 ** int(amount_asset["precision"]))

            # Get accounts involved
            from_account = api.getObject(op["from"])
            to_account   = api.getObject(op["to"])

            # Decode the memo
            memomsg = ""
            if "memo" in op :
                memo         = op["memo"]
                try :  # if possible
                    privkey = PrivateKey(config.memo_wif_key)
                    pubkey  = PublicKey(memo["from"], prefix=prefix)
                    memomsg = Memo.decode_memo(privkey, pubkey, memo["nonce"], memo["message"])
                except Exception as e:  # if not possible
                    memomsg = "--cannot decode-- %s" % str(e)
            # Print out
            print("last_op: %s | block:%s | from %s -> to: %s | fee: %f %s | amount: %f %s | memo: %s" % (
                  opID, block,
                  from_account["name"], to_account["name"],
                  fee_amount, fee_asset["symbol"],
                  amount_amount, amount_asset["symbol"],
                  memomsg))
Exemple #7
0
    def process_operations(self, operations):
        for operation in operations[::-1]:
            opID = operation["id"]
            block = operation["block_num"]
            op = operation["op"][1]

            if not "amount" in op:
                continue

            # Get assets involved in Fee and Transfer
            fee_asset = api.getObject(op["fee"]["asset_id"])
            amount_asset = api.getObject(op["amount"]["asset_id"])

            # Amounts for fee and transfer
            fee_amount = float(op["fee"]["amount"]) / float(10**int(
                fee_asset["precision"]))
            amount_amount = float(op["amount"]["amount"]) / float(10**int(
                amount_asset["precision"]))

            # Get accounts involved
            from_account = api.getObject(op["from"])
            to_account = api.getObject(op["to"])

            # Decode the memo
            memo = op["memo"]
            try:  # if possible
                privkey = PrivateKey(config.memo_wif_key)
                pubkey = PublicKey(memo["from"], prefix=prefix)
                memomsg = Memo.decode_memo(privkey, pubkey, memo["nonce"],
                                           memo["message"])
            except Exception as e:  # if not possible
                print("--cannot decode-- %s" % e)
                continue

            # Print out
            print(
                "last_op: %s | block:%s | from %s -> to: %s | fee: %f %s | amount: %f %s | memo: %s"
                % (opID, block, from_account["name"], to_account["name"],
                   fee_amount, fee_asset["symbol"], amount_amount,
                   amount_asset["symbol"], memomsg))

            # Parse the memo
            pattern = re.compile('[A-Z0-9]{3}-[A-Z0-9-]{8}')
            searchResults = pattern.search(memomsg)
            if not searchResults:
                continue
            ref_code = searchResults.group(0)

            email = ""
            pattern = re.compile('[a-z0-9][-a-z0-9_\+\.]*[a-z0-9]\@.+\.[a-z]+')
            searchResults = pattern.search(memomsg.lower())
            if searchResults:
                email = searchResults.group(0)

            # Request to Faucet
            headers = {'content-type': 'text/plain'}
            query = "refcode[code]=%s&refcode[account]=%s&refcode[asset_symbol]=%s&refcode[asset_amount]=%s&refcode[send_to]=%s" % (
                ref_code, from_account["name"], amount_asset["symbol"],
                op["amount"]["amount"], email)
            print("--- query: %s" % query)
            response = requests.post(config.faucet_url,
                                     params=query,
                                     headers=headers)