mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-28 06:25:49 +00:00
Serialization functions.
This commit is contained in:
50
Serializer.h
Normal file
50
Serializer.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef __SERIALIZER__
|
||||
#define __SERIALIZER__
|
||||
|
||||
#include <vector>
|
||||
#include "key.h"
|
||||
#include "uint256.h"
|
||||
|
||||
class Serializer
|
||||
{
|
||||
protected:
|
||||
std::vector<unsigned char> mData;
|
||||
|
||||
public:
|
||||
Serializer(int n=256) { mData.reserve(n); }
|
||||
Serializer(const std::vector<unsigned char> &data) : mData(data) { ; }
|
||||
|
||||
// assemble functions
|
||||
int add32(uint32); // ledger indexes, account sequence
|
||||
int add64(uint64); // timestamps, amounts
|
||||
int add160(const uint160&); // account names, hankos
|
||||
int add256(const uint256&); // transaction and ledger hashes
|
||||
int addRaw(const std::vector<unsigned char> &vector);
|
||||
|
||||
// disassemble functions
|
||||
bool get32(uint32&, int offset) const;
|
||||
bool get64(uint64&, int offset) const;
|
||||
bool get160(uint160&, int offset) const;
|
||||
bool get256(uint256&, int offset) const;
|
||||
bool getRaw(std::vector<unsigned char>&, int offset, int length) const;
|
||||
|
||||
// hash functions
|
||||
uint160 getRIPEMD160(int size=0) const;
|
||||
uint256 getSHA256(int size=0) const;
|
||||
uint256 getSHA512Half(int size=0) const;
|
||||
|
||||
// totality functions
|
||||
int getLength() const { return mData.size(); }
|
||||
const std::vector<unsigned char>& peekData() const { return mData; }
|
||||
std::vector<unsigned char> getData() const { return mData; }
|
||||
|
||||
// signature functions
|
||||
bool checkSignature(int pubkeyOffset, int signatureOffset) const;
|
||||
bool checkSignature(const std::vector<unsigned char> &signature, CKey& rkey) const;
|
||||
bool makeSignature(std::vector<unsigned char> &signature, CKey& rkey) const;
|
||||
bool addSignature(CKey& rkey);
|
||||
|
||||
static void UnitTest(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user