def myOwnUnpackerTxIn(self, val): data = val[38:] scriptsize, varintsize = unpackVarInt(data) data = val[38+varintsize:] scriptsize, varintsize = unpackVarInt(data[36:]) scriptend = 40 + varintsize + scriptsize print 'script length: %d, varintSize: %d, scriptEnd - dataSize: %d' % (scriptsize, varintsize, scriptend - len(data)) print 'len(val): %d' % (len(val)) dathash = val rtstr = ":".join("{0:x}".format(ord(c)) for c in dathash) print rtstr
def myOwnUnpackerTxIn(self, val): data = val[38:] scriptsize, varintsize = unpackVarInt(data) data = val[38 + varintsize:] scriptsize, varintsize = unpackVarInt(data[36:]) scriptend = 40 + varintsize + scriptsize print 'script length: %d, varintSize: %d, scriptEnd - dataSize: %d' % ( scriptsize, varintsize, scriptend - len(data)) print 'len(val): %d' % (len(val)) dathash = val rtstr = ":".join("{0:x}".format(ord(c)) for c in dathash) print rtstr
def getAllTxnByPrefix(self, Prefix): key = '\x04' + Prefix try: val = ArmoryDB.dbblkdata.Get(key) except: return None nCandidates = unpackVarInt(val) RtTxn = [] pos = nCandidates[1] for i in range(0, nCandidates[0]): key = '\x03' + val[pos +i*6:pos +(i+1)*6] rt = self.getTxnByKey(key) RtTxn.append(rt) return RtTxn
def getAllTxnByPrefix(self, Prefix): key = '\x04' + Prefix try: val = ArmoryDB.dbblkdata.Get(key) except: return None nCandidates = unpackVarInt(val) RtTxn = [] pos = nCandidates[1] for i in range(0, nCandidates[0]): key = '\x03' + val[pos + i * 6:pos + (i + 1) * 6] rt = self.getTxnByKey(key) RtTxn.append(rt) return RtTxn
def getTxnByHash(self, Hash): HashLeftOver = Hash[4:32] key = '\x04' + Hash[0:4] try: val = ArmoryDB.dbblkdata.Get(key) except: return None nCandidates = unpackVarInt(val) pos = nCandidates[1] for i in range(0, nCandidates[0]): key = '\x03' + val[pos +i*6:pos +(i+1)*6] Candidate = ArmoryDB.dbblkdata.Get(key) CandidateHash = Candidate[6:34] if(CandidateHash==HashLeftOver): return self.getTxnByKey(key) return None
def getTxnByHash(self, Hash): HashLeftOver = Hash[4:32] key = '\x04' + Hash[0:4] try: val = ArmoryDB.dbblkdata.Get(key) except: return None nCandidates = unpackVarInt(val) pos = nCandidates[1] for i in range(0, nCandidates[0]): key = '\x03' + val[pos + i * 6:pos + (i + 1) * 6] Candidate = ArmoryDB.dbblkdata.Get(key) CandidateHash = Candidate[6:34] if (CandidateHash == HashLeftOver): return self.getTxnByKey(key) return None
def myOwnUnpacker(self, val): data = val[2:] outputval = data[0:8] scriptsize, varintsize = unpackVarInt(data[8:]) scriptend = 8 + varintsize + scriptsize
def get(self, varType, sz=0, endianness=LITTLEENDIAN): """ First argument is the data-type: UINT32, VAR_INT, etc. If BINARY_CHUNK, need to supply a number of bytes to read, as well """ def sizeCheck(sz): if self.getRemainingSize()<sz: raise UnpackerError E = endianness pos = self.pos if varType == UINT32: sizeCheck(4) value = unpack(E+'I', self.binaryStr[pos:pos+4])[0] self.advance(4) return value elif varType == UINT64: sizeCheck(8) value = unpack(E+'Q', self.binaryStr[pos:pos+8])[0] self.advance(8) return value elif varType == UINT8: sizeCheck(1) value = unpack(E+'B', self.binaryStr[pos:pos+1])[0] self.advance(1) return value elif varType == UINT16: sizeCheck(2) value = unpack(E+'H', self.binaryStr[pos:pos+2])[0] self.advance(2) return value elif varType == INT32: sizeCheck(4) value = unpack(E+'i', self.binaryStr[pos:pos+4])[0] self.advance(4) return value elif varType == INT64: sizeCheck(8) value = unpack(E+'q', self.binaryStr[pos:pos+8])[0] self.advance(8) return value elif varType == INT8: sizeCheck(1) value = unpack(E+'b', self.binaryStr[pos:pos+1])[0] self.advance(1) return value elif varType == INT16: sizeCheck(2) value = unpack(E+'h', self.binaryStr[pos:pos+2])[0] self.advance(2) return value elif varType == VAR_INT: sizeCheck(1) [value, nBytes] = unpackVarInt(self.binaryStr[pos:pos+9]) self.advance(nBytes) return value elif varType == VAR_STR: sizeCheck(1) [value, nBytes] = unpackVarInt(self.binaryStr[pos:pos+9]) binOut = self.binaryStr[pos+nBytes:pos+nBytes+value] self.advance(nBytes+value) return binOut elif varType == FLOAT: sizeCheck(4) value = unpack(E+'f', self.binaryStr[pos:pos+4])[0] self.advance(4) return value elif varType == BINARY_CHUNK: sizeCheck(sz) binOut = self.binaryStr[pos:pos+sz] self.advance(sz) return binOut LOGERROR('Var Type not recognized! VarType = %d', varType) raise UnpackerError, "Var type not recognized! VarType="+str(varType)
def get(self, varType, sz=0, endianness=LITTLEENDIAN): """ First argument is the data-type: UINT32, VAR_INT, etc. If BINARY_CHUNK, need to supply a number of bytes to read, as well """ def sizeCheck(sz): if self.getRemainingSize() < sz: raise UnpackerError E = endianness pos = self.pos if varType == UINT32: sizeCheck(4) value = unpack(E + 'I', self.binaryStr[pos:pos + 4])[0] self.advance(4) return value elif varType == UINT64: sizeCheck(8) value = unpack(E + 'Q', self.binaryStr[pos:pos + 8])[0] self.advance(8) return value elif varType == UINT8: sizeCheck(1) value = unpack(E + 'B', self.binaryStr[pos:pos + 1])[0] self.advance(1) return value elif varType == UINT16: sizeCheck(2) value = unpack(E + 'H', self.binaryStr[pos:pos + 2])[0] self.advance(2) return value elif varType == INT32: sizeCheck(4) value = unpack(E + 'i', self.binaryStr[pos:pos + 4])[0] self.advance(4) return value elif varType == INT64: sizeCheck(8) value = unpack(E + 'q', self.binaryStr[pos:pos + 8])[0] self.advance(8) return value elif varType == INT8: sizeCheck(1) value = unpack(E + 'b', self.binaryStr[pos:pos + 1])[0] self.advance(1) return value elif varType == INT16: sizeCheck(2) value = unpack(E + 'h', self.binaryStr[pos:pos + 2])[0] self.advance(2) return value elif varType == VAR_INT: sizeCheck(1) [value, nBytes] = unpackVarInt(self.binaryStr[pos:pos + 9]) self.advance(nBytes) return value elif varType == VAR_STR: sizeCheck(1) [value, nBytes] = unpackVarInt(self.binaryStr[pos:pos + 9]) binOut = self.binaryStr[pos + nBytes:pos + nBytes + value] self.advance(nBytes + value) return binOut elif varType == FLOAT: sizeCheck(4) value = unpack(E + 'f', self.binaryStr[pos:pos + 4])[0] self.advance(4) return value elif varType == BINARY_CHUNK: sizeCheck(sz) binOut = self.binaryStr[pos:pos + sz] self.advance(sz) return binOut LOGERROR('Var Type not recognized! VarType = %d', varType) raise UnpackerError, "Var type not recognized! VarType=" + str( varType)