Example #1
0
    def BlockIn(self, payload=None):
        stream = BytesIO(payload)
        objc = aiptool.GetObj(VariStr().deserialize(stream).value)
        if objc is not None:
            obj = objc().deserialize(stream)
            if type(obj).__name__ != "Block":
                return PackMsg("BlockIn_r", VariStr("Wrong Block").serialize())
            re, msg = obj.Verification(self.db.bkheight + 1, self.db.aipdic)
            if re:
                re1, msg1 = self.db.VerifyBlockOnChain(obj)
                msg = msg + "--" + msg1
                ###clear the useless txs
                if re1:
                    if obj.blocktype.value in (0, 1):
                        poollaw, self.LawsPool = self.LawsPool, []
                        for law in poollaw:
                            if law not in obj.payloads.value:
                                self.LawsPool.append(law)
                    if obj.blocktype.value == 2:
                        pooltx, self.TxsPool = self.TxsPool, []
                        for tx in pooltx:
                            if tx not in obj.payloads.value:
                                self.TxsPool.append(tx)

                    ##for some report
                    self.record = self.ReadRecord()
                    self.record.append([obj.timestamp.value, len(obj.payloads), len(self.TxsPool),\
                    obj.POW(), obj.GetSize()])
                    self.SaveRecord()
                    ##
                ###clear the useless txs
            print(msg)
            return PackMsg("BlockIn_r", VariStr(msg).serialize())
        else:
            return PackMsg("BlockIn_r", VariStr("Wrong Block").serialize())
Example #2
0
 def Verification(self, currentheight, aipdic):
     if self.aipname.value != "aip1.aip1_0.Output":
         return False, "aip1.aip1_0.Output, item 1, False"
     if not aiptool.IsAipLegalForCurrentHeight(self.aipname.value,
                                               currentheight, aipdic):
         return False, "aip1.aip1_0.Output, item 1.1, False"
     ##verify aoc address
     if not aiptool.GetObj("aip0.aip0_0.Wallet").VerifyAddress(
             self.aocaddress.value):
         return False, "aip1.aip1_0.Output, item 2, False"
     return True, "aip1.aip1_0.Output, True"
Example #3
0
 def GetBlock(self, height):
     if self.p2p.Connect(MyNode=self.MyNode)[0]:
         pp = VariInt(height).serialize()
         func, payload = self.p2p.SendMsg(msgname="GetBlock",
                                          payload=pp,
                                          MyNode=self.MyNode)
     else:
         return None
     if payload is not None:
         stream = BytesIO(payload)
         return aiptool.GetObj(
             VariStr().deserialize(stream).value)().deserialize(stream)
Example #4
0
 def LawIn(self, payload=None):
     stream = BytesIO(payload)
     objc = aiptool.GetObj(VariStr().deserialize(stream).value)
     if objc is not None:
         obj = objc().deserialize(stream)
         if type(obj).__name__ != "Law":
             return PackMsg("LawIn_r", VariStr("Wrong Law").serialize())
         re, msg = obj.Verification(self.db.bkheight + 1, self.db.aipdic)
         if re and obj not in self.LawsPool:
             self.LawsPool.append(obj)
         return PackMsg("LawIn_r", VariStr(msg).serialize())
     else:
         return PackMsg("LawIn_r", VariStr("Wrong Law").serialize())
Example #5
0
 def LoadBlock(self, heightin, headermodel=False):
     if heightin < 0:
         return None
     tablename = "b" + str(int(heightin / 100000))
     with self.conn_b:
         bkdata = self.conn_b.execute(
             "SELECT height, DATA FROM " + tablename + " WHERE height = ?",
             (heightin, )).fetchone()
         stream = BytesIO(bkdata[1])
         bkobj = aiptool.GetObj(
             VariStr().deserialize(stream).value)().deserialize(stream)
         if headermodel:
             return HeaderNode().parse(bkobj)
         return bkobj
Example #6
0
    def Verification(self, currentheight, aipdic):
        if self.aipname.value != "aip2.aip2_0.Transaction_Gate":
            return False, "aip2.aip2_0.Transaction_Gate, item 1, False"
        if not aiptool.IsAipLegalForCurrentHeight(self.aipname.value,
                                                  currentheight, aipdic):
            return False, "aip2.aip2_0.Transaction_Gate, item 1.1, False"

        for inputi in self.withdraw:
            if inputi.aipname.value != "aip1.aip1_0.Input":
                return False, "aip2.aip2_0.Transaction_Gate, item 2, False"
            if inputi.pubkey.value != self.ownerpubkey.value:
                return False, "aip2.aip2_0.Transaction_Gate, item 2.1, False"
            re, msg = inputi.Verification(currentheight, aipdic)
            if not re:
                return False, "aip1.aip1_0.Transaction_Pay, item 2.2, False"

        for outputi in self.deposit:
            if outputi.aipname.value != "aip1.aip1_0.Output":
                return False, "aip2.aip2_0.Transaction_Gate, item 3, False"
            re, msg = outputi.Verification(currentheight, aipdic)
            if not re:
                return False, "aip2.aip2_0.Transaction_Gate, item 3.1, False"

        if self.token.value.lower() == "aoc":
            return False, "aip2.aip2_0.Transaction_Gate, item 4, False"

        if self.agreement.value != "this service is offered by aocpay, the ownerpubkey is responsible for any real law issue caused by this record":
            return False, "aip2.aip2_0.Transaction_Gate, item 5, False"

        msg1, msg2 = self.GetMsgSig()

        wallet = aiptool.GetObj("aip0.aip0_0.Wallet")
        try:
            re = wallet.VerifyMsg(self.ownerpubkey.value, msg1, self.sig.value)
        except:
            re = False
        if not re:
            return False, "aip2.aip2_0.Transaction_Gate, item 6, False"

        for os in self.ownerships:
            if os.aipname.value != "aip0.aip0_0.Ownership":
                return False, "aip2.aip2_0.Transaction_Gate, item 7.1, False"
            if msg2 != os.msg.value:
                return False, "aip2.aip2_0.Transaction_Gate, item 7.2, False"
            re, msg = os.Verification(currentheight, aipdic)
            if not re:
                return False, "aip2.aip2_0.Transaction_Gate, item 7.3, False " + msg

        return True, "aip2.aip2_0.Transaction_Gate, True"
Example #7
0
 def TxIn(self, payload=None):
     stream = BytesIO(payload)
     objc = aiptool.GetObj(VariStr().deserialize(stream).value)
     if objc is not None:
         obj = objc().deserialize(stream)
         if type(obj).__name__ not in ("Transaction_Pay",
                                       "Transaction_Gate"):
             return PackMsg("TxIn_r", VariStr("Wrong Tx Class").serialize())
         re, msg = obj.Verification(self.db.bkheight + 1, self.db.aipdic)
         if re and obj not in self.TxsPool:
             txs = list(self.TxsPool)
             txs.append(obj)
             ret, msgt = self.db.API_CheckTxsIfValid(txs)
             msg += "--" + msgt
             if ret:
                 self.TxsPool.append(obj)
         return PackMsg("TxIn_r", VariStr(msg).serialize())
     else:
         return PackMsg("TxIn_r", VariStr("Wrong Tx").serialize())
Example #8
0
    def Verification(self, currentheight, aipdic):
        ##1 the protocol name should be the same
        if self.aipname.value != "aip0.aip0_0.Ownership":
            return False, "aip0.aip0_0.Ownership, item 1, False"

        if not aiptool.IsAipLegalForCurrentHeight(self.aipname.value,
                                                  currentheight, aipdic):
            return False, "aip0.aip0_0.Ownership, item 1.1, False"

        #2 the msg should be verified
        wallet = aiptool.GetObj("aip0.aip0_0.Wallet")
        try:
            re = wallet.VerifyMsg(self.pubkey.value, self.msg.value,
                                  self.sig.value)
        except:
            re = False
        if not re:
            return False, "aip0.aip0_0.Ownership, item 2, False"

        return True, "aip0.aip0_0.Ownership, True"
Example #9
0
    def Verification(self, currentheight, aipdic):
        if self.aipname.value != "aip1.aip1_0.Transaction_Pay":
            return False, "aip1.aip1_0.Transaction_Pay, item 1, False"
        if not aiptool.IsAipLegalForCurrentHeight(self.aipname.value,
                                                  currentheight, aipdic):
            return False, "aip1.aip1_0.Transaction_Pay, item 1.1, False"
        ##3 Length of inputs and sigs should equal, integration or normal transaction
        txid = self.GetTxType()
        if txid == 0:
            return False, "aip1.aip1_0.Transaction_Pay, item 2, False"
        ##4
        for outputi in self.outputs:
            if outputi.aipname.value != "aip1.aip1_0.Output":
                return False, "aip1.aip1_0.Transaction_Pay, item 3, False"
            re, msg = outputi.Verification(currentheight, aipdic)
            if not re:
                return False, "aip1.aip1_0.Transaction_Pay, item 3.1, False"
        ##5
        msgsig = self.GetMsgSig()
        wallet = aiptool.GetObj("aip0.aip0_0.Wallet")
        #"""if is normal transaction or integration transaction"""
        for idd, inputi in enumerate(self.inputs):
            if inputi.aipname.value != "aip1.aip1_0.Input":
                return False, "aip1.aip1_0.Transaction_Pay, item 4, False"
            re, msg = inputi.Verification(currentheight, aipdic)
            if not re:
                return False, "aip1.aip1_0.Transaction_Pay, item 4.1, False"
            if txid == 1:
                sig = self.sigs.value[idd].value
            elif txid == 2:
                sig = self.sigs.value[0].value
            try:
                rew = wallet.VerifyMsg(inputi.pubkey.value, msgsig, sig)
            except:
                rew = False
            if not rew:
                return False, "aip1.aip1_0.Transaction_Pay, item 4.2, False"

        return True, "aip1.aip1_0.Transaction_Pay, True"