mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
.
This commit is contained in:
58
Ledger.cpp
58
Ledger.cpp
@@ -96,6 +96,8 @@ Ledger::pointer Ledger::getParent()
|
|||||||
return(mParent);
|
return(mParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: we can optimize so the ledgers only hold the delta from the accepted ledger
|
||||||
|
// TODO: check to make sure the ledger is consistent after we load it
|
||||||
bool Ledger::load(uint256& hash)
|
bool Ledger::load(uint256& hash)
|
||||||
{
|
{
|
||||||
Database* db=theApp->getDB();
|
Database* db=theApp->getDB();
|
||||||
@@ -107,8 +109,60 @@ bool Ledger::load(uint256& hash)
|
|||||||
|
|
||||||
if(db->executeSQL(sql.c_str()))
|
if(db->executeSQL(sql.c_str()))
|
||||||
{
|
{
|
||||||
db->getNextRow();
|
if(db->getNextRow())
|
||||||
sql="SELECT * from Transactions where "
|
{
|
||||||
|
mIndex=db->getInt("LedgerIndex");
|
||||||
|
mHash=hash;
|
||||||
|
mValidSig=false;
|
||||||
|
mAccounts.clear();
|
||||||
|
mTransactions.clear();
|
||||||
|
mDiscardedTransactions.clear();
|
||||||
|
|
||||||
|
db->getBinary("ParentHash",mParentHash.begin(),mParentHash.GetSerializeSize());
|
||||||
|
mFeeHeld=db->getBigInt("FeeHeld");
|
||||||
|
|
||||||
|
|
||||||
|
char buf[100];
|
||||||
|
sql="SELECT Transactions.* from Transactions,LedgerTransactionMap where Transactions.TransactionID=LedgerTransactionMap.TransactionID and LedgerTransactionMap.LedgerID=";
|
||||||
|
sql.append(itoa( db->getInt(0),buf,10) );
|
||||||
|
if(db->executeSQL(sql.c_str()))
|
||||||
|
{
|
||||||
|
unsigned char tbuf[1000];
|
||||||
|
while(db->getNextRow())
|
||||||
|
{
|
||||||
|
TransactionPtr trans=TransactionPtr(new newcoin::Transaction());
|
||||||
|
trans->set_amount( db->getBigInt("Amount"));
|
||||||
|
trans->set_seqnum( db->getInt("seqnum"));
|
||||||
|
trans->set_ledgerindex( db->getInt("ledgerIndex"));
|
||||||
|
db->getBinary("from",tbuf,1000);
|
||||||
|
trans->set_from(tbuf,20);
|
||||||
|
db->getBinary("dest",tbuf,1000);
|
||||||
|
trans->set_dest(tbuf,20);
|
||||||
|
db->getBinary("pubkey",tbuf,1000);
|
||||||
|
trans->set_pubkey(tbuf,128);
|
||||||
|
db->getBinary("sig",tbuf,1000);
|
||||||
|
trans->set_sig(tbuf,32);
|
||||||
|
|
||||||
|
mTransactions.push_back(trans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sql="SELECT Accounts.* from Acconts,LedgerAcountMap where Accounts.AccountID=LedgerAccountMap.AccountID and LedgerAccountMap.LedgerID=";
|
||||||
|
sql.append(buf);
|
||||||
|
if(db->executeSQL(sql.c_str()))
|
||||||
|
{
|
||||||
|
while(db->getNextRow())
|
||||||
|
{
|
||||||
|
uint160 address;
|
||||||
|
db->getBinary("Address",address.begin(),address.GetSerializeSize());
|
||||||
|
|
||||||
|
mAccounts[address].first=db->getBigInt("Amount");
|
||||||
|
mAccounts[address].second=db->getInt("SeqNum");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|||||||
3
Ledger.h
3
Ledger.h
@@ -26,8 +26,7 @@ private:
|
|||||||
uint256 mSignature;
|
uint256 mSignature;
|
||||||
uint256 mParentHash;
|
uint256 mParentHash;
|
||||||
uint32 mValidationSeqNum;
|
uint32 mValidationSeqNum;
|
||||||
|
uint64 mFeeHeld;
|
||||||
|
|
||||||
|
|
||||||
std::map<uint160, Account > mAccounts;
|
std::map<uint160, Account > mAccounts;
|
||||||
std::list<TransactionPtr> mTransactions;
|
std::list<TransactionPtr> mTransactions;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public:
|
|||||||
//void load();
|
//void load();
|
||||||
//void save();
|
//void save();
|
||||||
|
|
||||||
void addNode(uint160& hanko,uint1024& publicKey);
|
void addNode(uint160& hanko,std::vector<unsigned char>& publicKey);
|
||||||
void removeNode(uint160& hanko);
|
void removeNode(uint160& hanko);
|
||||||
|
|
||||||
// 0- we don't care, 1- we care and is valid, 2-invalid signature
|
// 0- we don't care, 1- we care and is valid, 2-invalid signature
|
||||||
|
|||||||
@@ -1,10 +1,74 @@
|
|||||||
#include "SqliteDatabase.h"
|
#include "SqliteDatabase.h"
|
||||||
|
|
||||||
SqliteDatabase::SqliteDatabase()
|
SqliteDatabase::SqliteDatabase() : Database
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SqliteDatabase::connect()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void SqliteDatabase::disconnect()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if the query went ok
|
||||||
|
bool SqliteDatabase::executeSQL(const char* sql)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// tells you how many rows were changed by an update or insert
|
||||||
|
int SqliteDatabase::getNumRowsAffected()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns false if there are no results
|
||||||
|
bool SqliteDatabase::startIterRows()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void SqliteDatabase::endIterRows()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// call this after you executeSQL
|
||||||
|
// will return false if there are no more rows
|
||||||
|
bool SqliteDatabase::getNextRow()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
char* SqliteDatabase::getStr(int colIndex,std::string& retStr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
int32 SqliteDatabase::getInt(int colIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
float SqliteDatabase::getFloat(int colIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
bool SqliteDatabase::getBool(int colIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
bool SqliteDatabase::getBinary(int colIndex,unsigned char* buf,int maxSize)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
uint64 SqliteDatabase::getBigInt(int colIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* http://www.sqlite.org/lang_expr.html
|
/* http://www.sqlite.org/lang_expr.html
|
||||||
BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. For example:
|
BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. For example:
|
||||||
X'53514C697465'
|
X'53514C697465'
|
||||||
|
|||||||
@@ -5,6 +5,29 @@ class SqliteDatabase : public Database
|
|||||||
public:
|
public:
|
||||||
SqliteDatabase();
|
SqliteDatabase();
|
||||||
|
|
||||||
|
void connect();
|
||||||
|
void disconnect();
|
||||||
|
|
||||||
|
// returns true if the query went ok
|
||||||
|
bool executeSQL(const char* sql);
|
||||||
|
|
||||||
|
// tells you how many rows were changed by an update or insert
|
||||||
|
int getNumRowsAffected();
|
||||||
|
|
||||||
|
// returns false if there are no results
|
||||||
|
bool startIterRows();
|
||||||
|
void endIterRows();
|
||||||
|
|
||||||
|
// call this after you executeSQL
|
||||||
|
// will return false if there are no more rows
|
||||||
|
bool getNextRow();
|
||||||
|
|
||||||
|
char* getStr(int colIndex,std::string& retStr);
|
||||||
|
int32 getInt(int colIndex);
|
||||||
|
float getFloat(int colIndex);
|
||||||
|
bool getBool(int colIndex);
|
||||||
|
bool getBinary(int colIndex,unsigned char* buf,int maxSize);
|
||||||
|
uint64 getBigInt(int colIndex);
|
||||||
|
|
||||||
void escape(unsigned char* start,int size,std::string& retStr);
|
void escape(unsigned char* start,int size,std::string& retStr);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "../utillib/reportingmechanism.h"
|
|
||||||
#include "string/i4string.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ char* Database::getStr(const char* colName,std::string& retStr)
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
w32 Database::getInt(const char* colName)
|
int32 Database::getInt(const char* colName)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
if(getColNumber(colName,&index))
|
if(getColNumber(colName,&index))
|
||||||
@@ -56,6 +54,26 @@ bool Database::getBool(const char* colName)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Database::getBinary(const char* colName,unsigned char* buf,int maxSize)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
if(getColNumber(colName,&index))
|
||||||
|
{
|
||||||
|
return(getBinary(index,buf,maxSize));
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 Database::getBigInt(const char* colName)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
if(getColNumber(colName,&index))
|
||||||
|
{
|
||||||
|
return(getBigInt(index));
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// returns false if can't find col
|
// returns false if can't find col
|
||||||
@@ -63,7 +81,7 @@ bool Database::getColNumber(const char* colName,int* retIndex)
|
|||||||
{
|
{
|
||||||
for(int n=0; n<mNumCol; n++)
|
for(int n=0; n<mNumCol; n++)
|
||||||
{
|
{
|
||||||
if(i4_stricmp(colName,mColNameTable[n])==0)
|
if(stricmp(colName,mColNameTable[n].c_str())==0)
|
||||||
{
|
{
|
||||||
*retIndex=n;
|
*retIndex=n;
|
||||||
return(true);
|
return(true);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define __DATABASE__
|
#define __DATABASE__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../types.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
this maintains the connection to the database
|
this maintains the connection to the database
|
||||||
@@ -10,10 +11,10 @@ class Database
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
int mNumCol;
|
int mNumCol;
|
||||||
std:string mUser;
|
std::string mUser;
|
||||||
std:string mHost;
|
std::string mHost;
|
||||||
std:string mDBPass;
|
std::string mDBPass;
|
||||||
std:string* mColNameTable;
|
std::string* mColNameTable;
|
||||||
|
|
||||||
bool getColNumber(const char* colName, int* retIndex);
|
bool getColNumber(const char* colName, int* retIndex);
|
||||||
|
|
||||||
@@ -48,13 +49,15 @@ public:
|
|||||||
int32 getInt(const char* colName);
|
int32 getInt(const char* colName);
|
||||||
float getFloat(const char* colName);
|
float getFloat(const char* colName);
|
||||||
bool getBool(const char* colName);
|
bool getBool(const char* colName);
|
||||||
bool getBinary(const char* colName,char* buf,int maxSize);
|
bool getBinary(const char* colName,unsigned char* buf,int maxSize);
|
||||||
|
uint64 getBigInt(const char* colName);
|
||||||
|
|
||||||
virtual char* getStr(int colIndex,std::string& retStr)=0;
|
virtual char* getStr(int colIndex,std::string& retStr)=0;
|
||||||
virtual int32 getInt(int colIndex)=0;
|
virtual int32 getInt(int colIndex)=0;
|
||||||
virtual float getFloat(int colIndex)=0;
|
virtual float getFloat(int colIndex)=0;
|
||||||
virtual bool getBool(int colIndex)=0;
|
virtual bool getBool(int colIndex)=0;
|
||||||
virtual bool getBinary(int colIndex,char* buf,int maxSize)=0;
|
virtual bool getBinary(int colIndex,unsigned char* buf,int maxSize)=0;
|
||||||
|
virtual uint64 getBigInt(int colIndex)=0;
|
||||||
|
|
||||||
int getSingleDBValueInt(const char* sql);
|
int getSingleDBValueInt(const char* sql);
|
||||||
float getSingleDBValueFloat(const char* sql);
|
float getSingleDBValueFloat(const char* sql);
|
||||||
@@ -63,11 +66,5 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class MsqlDatabase
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
2
types.h
2
types.h
@@ -3,12 +3,14 @@
|
|||||||
typedef __int64 int64;
|
typedef __int64 int64;
|
||||||
typedef unsigned __int64 uint64;
|
typedef unsigned __int64 uint64;
|
||||||
typedef unsigned int uint32;
|
typedef unsigned int uint32;
|
||||||
|
typedef int int32;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
typedef long long int64;
|
typedef long long int64;
|
||||||
typedef unsigned long long uint64;
|
typedef unsigned long long uint64;
|
||||||
typedef unsigned int uint32;
|
typedef unsigned int uint32;
|
||||||
|
typedef int int32;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1300
|
#if defined(_MSC_VER) && _MSC_VER < 1300
|
||||||
|
|||||||
Reference in New Issue
Block a user