bool CBInitVersionChecksumBytesFromBytes(CBVersionChecksumBytes * self,uint8_t * bytes,uint32_t size,bool cacheString,void (*logError)(char *,...)) { self->cacheString = cacheString; self->cachedString = NULL; if (NOT CBInitByteArrayWithData(CBGetByteArray(self), bytes, size, logError)) return false; return true; }
bool CBInitVersionChecksumBytesFromBytes(CBVersionChecksumBytes * self,uint8_t * bytes,uint32_t size,bool cacheString,CBEvents * events){ self->cacheString = cacheString; self->cachedString = NULL; if (NOT CBInitByteArrayWithData(CBGetByteArray(self), bytes, size, events)) return false; return true; }
CBByteArray * CBNewByteArrayWithData(uint8_t * data,uint32_t size,void (*logError)(char *,...)){ CBByteArray * self = malloc(sizeof(*self)); if (NOT self) { logError("Cannot allocate %i bytes of memory in CBNewByteArrayWithData\n",sizeof(*self)); return NULL; } CBGetObject(self)->free = CBFreeByteArray; if(CBInitByteArrayWithData(self, data, size, logError)) return self; free(self); return NULL; }
bool CBInitVersionChecksumBytesFromString(CBVersionChecksumBytes * self,CBByteArray * string,bool cacheString,void (*logError)(char *,...)) { // Cache string if needed if (cacheString) { self->cachedString = string; CBRetainObject(string); } else self->cachedString = NULL; self->cacheString = cacheString; // Get bytes from string conversion CBBigInt bytes; CBBigIntAlloc(&bytes, 25); // 25 is the number of bytes for bitcoin addresses. if (NOT CBDecodeBase58Checked(&bytes, (char *)CBByteArrayGetData(string), logError)) return false; // Take over the bytes with the CBByteArray if (NOT CBInitByteArrayWithData(CBGetByteArray(self), bytes.data, bytes.length, logError)) return false; CBByteArrayReverseBytes(CBGetByteArray(self)); // CBBigInt is in little-endian. Conversion needed to make bitcoin address the right way. return true; }
bool CBInitVersionChecksumBytesFromString(CBVersionChecksumBytes * self,CBByteArray * string,bool cacheString,CBEvents * events){ // Cache string if needed if (cacheString) { self->cachedString = string; CBRetainObject(string); }else self->cachedString = NULL; self->cacheString = cacheString; // Get bytes from string conversion CBBigInt bytes = CBDecodeBase58Checked((char *)CBByteArrayGetData(string), events); if (bytes.length == 1) { return false; } // Take over the bytes with the CBByteArray if (NOT CBInitByteArrayWithData(CBGetByteArray(self), bytes.data, bytes.length, events)) return false; CBByteArrayReverseBytes(CBGetByteArray(self)); // CBBigInt is in little-endian. Conversion needed to make bitcoin address the right way. return true; }
CBByteArray * CBNewByteArrayWithData(uint8_t * data, uint32_t size) { CBByteArray * self = malloc(sizeof(*self)); CBGetObject(self)->free = CBFreeByteArray; CBInitByteArrayWithData(self, data, size); return self; }