mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Merge branch 'create'
This commit is contained in:
@@ -31,7 +31,7 @@ public:
|
|||||||
AccountState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger
|
AccountState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger
|
||||||
|
|
||||||
const NewcoinAddress& getAccountID() const { return mAccountID; }
|
const NewcoinAddress& getAccountID() const { return mAccountID; }
|
||||||
uint64 getBalance() const { return mLedgerEntry->getIFieldU64(sfBalance); }
|
STAmount getBalance() const { return mLedgerEntry->getIValueFieldAmount(sfBalance); }
|
||||||
uint32 getSeq() const { return mLedgerEntry->getIFieldU32(sfSequence); }
|
uint32 getSeq() const { return mLedgerEntry->getIFieldU32(sfSequence); }
|
||||||
|
|
||||||
SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; }
|
SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; }
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Ledger::Ledger(const NewcoinAddress& masterID, uint64 startAmount) : mTotCoins(s
|
|||||||
|
|
||||||
// special case: put coins in root account
|
// special case: put coins in root account
|
||||||
AccountState::pointer startAccount = boost::make_shared<AccountState>(masterID);
|
AccountState::pointer startAccount = boost::make_shared<AccountState>(masterID);
|
||||||
startAccount->peekSLE().setIFieldU64(sfBalance, startAmount);
|
startAccount->peekSLE().setIFieldAmount(sfBalance, startAmount);
|
||||||
startAccount->peekSLE().setIFieldU32(sfSequence, 1);
|
startAccount->peekSLE().setIFieldU32(sfSequence, 1);
|
||||||
writeBack(lepCREATE, startAccount->getSLE());
|
writeBack(lepCREATE, startAccount->getSLE());
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -55,7 +55,7 @@ Ledger::Ledger(Ledger::pointer prevLedger) : mParentHash(prevLedger->getHash()),
|
|||||||
mCloseTime = prevLedger->getNextLedgerClose();
|
mCloseTime = prevLedger->getNextLedgerClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mTotCoins(0), mCloseTime(0),
|
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mCloseTime(0),
|
||||||
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
||||||
{
|
{
|
||||||
Serializer s(rawLedger);
|
Serializer s(rawLedger);
|
||||||
@@ -75,7 +75,7 @@ Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mTotCoins(0), mClo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::Ledger(const std::string& rawLedger) : mTotCoins(0), mCloseTime(0),
|
Ledger::Ledger(const std::string& rawLedger) : mCloseTime(0),
|
||||||
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
||||||
{
|
{
|
||||||
Serializer s(rawLedger);
|
Serializer s(rawLedger);
|
||||||
@@ -154,11 +154,11 @@ bool Ledger::addTransaction(Transaction::pointer trans)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ledger::addTransaction(const uint256& txID, const Serializer& txn, uint64_t fee)
|
bool Ledger::addTransaction(const uint256& txID, const Serializer& txn, STAmount saPaid)
|
||||||
{ // low-level - just add to table
|
{ // low-level - just add to table
|
||||||
SHAMapItem::pointer item = boost::make_shared<SHAMapItem>(txID, txn.peekData());
|
SHAMapItem::pointer item = boost::make_shared<SHAMapItem>(txID, txn.peekData());
|
||||||
if (!mTransactionMap->addGiveItem(item, true)) return false;
|
if (!mTransactionMap->addGiveItem(item, true)) return false;
|
||||||
mTotCoins -= fee;
|
mTotCoins -= saPaid;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool addTransaction(Transaction::pointer);
|
bool addTransaction(Transaction::pointer);
|
||||||
bool addTransaction(const uint256& id, const Serializer& txn, uint64_t fee);
|
bool addTransaction(const uint256& id, const Serializer& txn, STAmount saPaid);
|
||||||
|
|
||||||
static Ledger::pointer getSQL(const std::string& sqlStatement);
|
static Ledger::pointer getSQL(const std::string& sqlStatement);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public:
|
|||||||
const uint256& getParentHash() const { return mParentHash; }
|
const uint256& getParentHash() const { return mParentHash; }
|
||||||
const uint256& getTransHash() const { return mTransHash; }
|
const uint256& getTransHash() const { return mTransHash; }
|
||||||
const uint256& getAccountHash() const { return mAccountHash; }
|
const uint256& getAccountHash() const { return mAccountHash; }
|
||||||
uint64 getTotalCoins() const { return mTotCoins; }
|
STAmount getTotalCoins() const { return mTotCoins; }
|
||||||
uint64 getCloseTimeNC() const { return mCloseTime; }
|
uint64 getCloseTimeNC() const { return mCloseTime; }
|
||||||
uint32 getLedgerSeq() const { return mLedgerSeq; }
|
uint32 getLedgerSeq() const { return mLedgerSeq; }
|
||||||
uint16 getInterval() const { return mLedgerInterval; }
|
uint16 getInterval() const { return mLedgerInterval; }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ LedgerEntryFormat LedgerFormats[]=
|
|||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Balance), STI_UINT64, SOE_REQUIRED, 0 },
|
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 },
|
{ S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(LastTxn), STI_UINT32, SOE_REQUIRED, 0 },
|
{ S_FIELD(LastTxn), STI_UINT32, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(AuthorizedKey),STI_HASH160, SOE_IFFLAG, 1 },
|
{ S_FIELD(AuthorizedKey),STI_HASH160, SOE_IFFLAG, 1 },
|
||||||
@@ -39,12 +39,11 @@ LedgerEntryFormat LedgerFormats[]=
|
|||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||||
{ S_FIELD(Borrower), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Borrower), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Lender), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Lender), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
|
|
||||||
{ S_FIELD(Limit), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Limit), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(CurrentRate), STI_UINT32, SOE_IFFLAG, 2 },
|
{ S_FIELD(CurrentRate), STI_UINT32, SOE_IFFLAG, 1 },
|
||||||
{ S_FIELD(RateLock), STI_UINT32, SOE_IFFLAG, 4 },
|
{ S_FIELD(RateLock), STI_UINT32, SOE_IFFLAG, 2 },
|
||||||
{ S_FIELD(NextRate), STI_UINT32, SOE_IFFLAG, 8 },
|
{ S_FIELD(NextRate), STI_UINT32, SOE_IFFLAG, 4 },
|
||||||
{ S_FIELD(NextRateLgr), STI_UINT32, SOE_IFFLAG, 8 },
|
{ S_FIELD(NextRateLgr), STI_UINT32, SOE_IFFLAG, 8 },
|
||||||
{ S_FIELD(NextRateExp), STI_UINT32, SOE_IFFLAG, 16 },
|
{ S_FIELD(NextRateExp), STI_UINT32, SOE_IFFLAG, 16 },
|
||||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||||
|
|||||||
@@ -618,7 +618,7 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
|
|||||||
naRegular0Public.getAccountPublic(),
|
naRegular0Public.getAccountPublic(),
|
||||||
vucGeneratorSig);
|
vucGeneratorSig);
|
||||||
|
|
||||||
(void) theApp->getOPs().processTransaction(trns);
|
// (void) theApp->getOPs().processTransaction(trns);
|
||||||
|
|
||||||
Json::Value obj(Json::objectValue);
|
Json::Value obj(Json::objectValue);
|
||||||
|
|
||||||
@@ -691,10 +691,11 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|||||||
return "source account does not exist";
|
return "source account does not exist";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 uSrcBalance = sleSrc->getIFieldU64(sfBalance);
|
STAmount saSrcBalance = sleSrc->getIValueFieldAmount(sfBalance);
|
||||||
uint64 uInitialFunds = (params.size() < 4) ? 0 : boost::lexical_cast<uint64>(params[3u].asString());
|
STAmount saInitialFunds = (params.size() < 4) ? 0 : boost::lexical_cast<uint64>(params[3u].asString());
|
||||||
|
|
||||||
if (uSrcBalance < theConfig.FEE_CREATE + uInitialFunds)
|
#if 0
|
||||||
|
if (saSrcBalance < theConfig.FEE_CREATE + saInitialFunds)
|
||||||
{
|
{
|
||||||
return "insufficent funds";
|
return "insufficent funds";
|
||||||
}
|
}
|
||||||
@@ -702,7 +703,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|||||||
{
|
{
|
||||||
return "source account has not been claimed";
|
return "source account has not been claimed";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
NewcoinAddress naRegularGenerator;
|
NewcoinAddress naRegularGenerator;
|
||||||
NewcoinAddress naRegular0Public;
|
NewcoinAddress naRegular0Public;
|
||||||
NewcoinAddress naRegular0Private;
|
NewcoinAddress naRegular0Private;
|
||||||
@@ -765,7 +766,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
|||||||
theConfig.FEE_CREATE,
|
theConfig.FEE_CREATE,
|
||||||
0, // YYY No source tag
|
0, // YYY No source tag
|
||||||
naCreateID,
|
naCreateID,
|
||||||
uInitialFunds); // Initial funds in XNC.
|
saInitialFunds); // Initial funds in XNC.
|
||||||
|
|
||||||
(void) theApp->getOPs().processTransaction(trans);
|
(void) theApp->getOPs().processTransaction(trans);
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public:
|
|||||||
{ return mObject.setValueFieldAccount(field, account); }
|
{ return mObject.setValueFieldAccount(field, account); }
|
||||||
void setIFieldAccount(SOE_Field field, const NewcoinAddress& account)
|
void setIFieldAccount(SOE_Field field, const NewcoinAddress& account)
|
||||||
{ return mObject.setValueFieldAccount(field, account); }
|
{ return mObject.setValueFieldAccount(field, account); }
|
||||||
void setIFeldAmount(SOE_Field field, const STAmount& amount)
|
void setIFieldAmount(SOE_Field field, const STAmount& amount)
|
||||||
{ return mObject.setValueFieldAmount(field, amount); }
|
{ return mObject.setValueFieldAmount(field, amount); }
|
||||||
|
|
||||||
bool getIFieldPresent(SOE_Field field) const { return mObject.isFieldPresent(field); }
|
bool getIFieldPresent(SOE_Field field) const { return mObject.isFieldPresent(field); }
|
||||||
|
|||||||
@@ -160,18 +160,18 @@ void SerializedTransaction::setVersion(uint32 ver)
|
|||||||
v->setValue(ver);
|
v->setValue(ver);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 SerializedTransaction::getTransactionFee() const
|
STAmount SerializedTransaction::getTransactionFee() const
|
||||||
{
|
{
|
||||||
const STUInt64* v = dynamic_cast<const STUInt64*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
const STAmount* v = dynamic_cast<const STAmount*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
return v->getValue();
|
return v->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializedTransaction::setTransactionFee(uint64 fee)
|
void SerializedTransaction::setTransactionFee(STAmount saFee)
|
||||||
{
|
{
|
||||||
STUInt64* v = dynamic_cast<STUInt64*>(mMiddleTxn.getPIndex(TransactionIFee));
|
STUInt64* v = dynamic_cast<STUInt64*>(mMiddleTxn.getPIndex(TransactionIFee));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
v->setValue(fee);
|
v->setValue(saFee);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 SerializedTransaction::getSequence() const
|
uint32 SerializedTransaction::getSequence() const
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ public:
|
|||||||
void setVersion(uint32);
|
void setVersion(uint32);
|
||||||
|
|
||||||
TransactionType getTxnType() const { return mType; }
|
TransactionType getTxnType() const { return mType; }
|
||||||
uint64 getTransactionFee() const;
|
STAmount getTransactionFee() const;
|
||||||
void setTransactionFee(uint64);
|
void setTransactionFee(STAmount saFee);
|
||||||
|
|
||||||
const NewcoinAddress& getSourceAccount() const { return mSourceAccount; }
|
const NewcoinAddress& getSourceAccount() const { return mSourceAccount; }
|
||||||
std::vector<unsigned char> getSigningPubKey() const;
|
std::vector<unsigned char> getSigningPubKey() const;
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ public:
|
|||||||
friend STAmount divide(const STAmount& v1, const STAmount& v2, const uint160& currencyOut);
|
friend STAmount divide(const STAmount& v1, const STAmount& v2, const uint160& currencyOut);
|
||||||
friend STAmount multiply(const STAmount& v1, const STAmount& v2, const uint160& currencyOut);
|
friend STAmount multiply(const STAmount& v1, const STAmount& v2, const uint160& currencyOut);
|
||||||
|
|
||||||
// Someone iis offering X for Y, what is the rate?
|
// Someone is offering X for Y, what is the rate?
|
||||||
friend uint64 getRate(const STAmount& offerOut, const STAmount& offerIn);
|
friend uint64 getRate(const STAmount& offerOut, const STAmount& offerIn);
|
||||||
|
|
||||||
// Someone is offering X for Y, I try to pay Z, how much do I get?
|
// Someone is offering X for Y, I try to pay Z, how much do I get?
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ Transaction::Transaction(
|
|||||||
const NewcoinAddress& naPublicKey,
|
const NewcoinAddress& naPublicKey,
|
||||||
const NewcoinAddress& naSourceAccount,
|
const NewcoinAddress& naSourceAccount,
|
||||||
uint32 uSeq,
|
uint32 uSeq,
|
||||||
uint64 uFee,
|
STAmount saFee,
|
||||||
uint32 uSourceTag) :
|
uint32 uSourceTag) :
|
||||||
mStatus(NEW)
|
mStatus(NEW)
|
||||||
{
|
{
|
||||||
@@ -71,7 +71,7 @@ Transaction::Transaction(
|
|||||||
mTransaction->setSigningPubKey(mFromPubKey);
|
mTransaction->setSigningPubKey(mFromPubKey);
|
||||||
mTransaction->setSourceAccount(mAccountFrom);
|
mTransaction->setSourceAccount(mAccountFrom);
|
||||||
mTransaction->setSequence(uSeq);
|
mTransaction->setSequence(uSeq);
|
||||||
mTransaction->setTransactionFee(uFee);
|
mTransaction->setTransactionFee(saFee);
|
||||||
|
|
||||||
if (uSourceTag)
|
if (uSourceTag)
|
||||||
{
|
{
|
||||||
@@ -155,7 +155,7 @@ Transaction::pointer Transaction::sharedClaim(
|
|||||||
Transaction::pointer Transaction::setCreate(
|
Transaction::pointer Transaction::setCreate(
|
||||||
const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& naCreateAccountID,
|
const NewcoinAddress& naCreateAccountID,
|
||||||
uint64 uFund)
|
STAmount uFund)
|
||||||
{
|
{
|
||||||
mTransaction->setITFieldU32(sfFlags, tfCreateAccount);
|
mTransaction->setITFieldU32(sfFlags, tfCreateAccount);
|
||||||
mTransaction->setITFieldAccount(sfDestination, naCreateAccountID);
|
mTransaction->setITFieldAccount(sfDestination, naCreateAccountID);
|
||||||
@@ -170,14 +170,14 @@ Transaction::pointer Transaction::sharedCreate(
|
|||||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& naSourceAccount,
|
const NewcoinAddress& naSourceAccount,
|
||||||
uint32 uSeq,
|
uint32 uSeq,
|
||||||
uint64 uFee,
|
STAmount saFee,
|
||||||
uint32 uSourceTag,
|
uint32 uSourceTag,
|
||||||
const NewcoinAddress& naCreateAccountID,
|
const NewcoinAddress& naCreateAccountID,
|
||||||
uint64 uFund)
|
STAmount uFund)
|
||||||
{
|
{
|
||||||
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
|
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
|
||||||
naPublicKey, naSourceAccount,
|
naPublicKey, naSourceAccount,
|
||||||
uSeq, uFee, uSourceTag);
|
uSeq, saFee, uSourceTag);
|
||||||
|
|
||||||
return tResult->setCreate(naPrivateKey, naCreateAccountID, uFund);
|
return tResult->setCreate(naPrivateKey, naCreateAccountID, uFund);
|
||||||
}
|
}
|
||||||
@@ -189,10 +189,10 @@ Transaction::pointer Transaction::sharedCreate(
|
|||||||
Transaction::pointer Transaction::setPayment(
|
Transaction::pointer Transaction::setPayment(
|
||||||
const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& toAccount,
|
const NewcoinAddress& toAccount,
|
||||||
uint64 uAmount)
|
STAmount saAmount)
|
||||||
{
|
{
|
||||||
mTransaction->setITFieldAccount(sfDestination, toAccount);
|
mTransaction->setITFieldAccount(sfDestination, toAccount);
|
||||||
mTransaction->setITFieldU64(sfAmount, uAmount);
|
mTransaction->setITFieldU64(sfAmount, saAmount);
|
||||||
|
|
||||||
sign(naPrivateKey);
|
sign(naPrivateKey);
|
||||||
|
|
||||||
@@ -203,16 +203,16 @@ Transaction::pointer Transaction::sharedPayment(
|
|||||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& naSourceAccount,
|
const NewcoinAddress& naSourceAccount,
|
||||||
uint32 uSeq,
|
uint32 uSeq,
|
||||||
uint64 uFee,
|
STAmount saFee,
|
||||||
uint32 uSourceTag,
|
uint32 uSourceTag,
|
||||||
const NewcoinAddress& toAccount,
|
const NewcoinAddress& toAccount,
|
||||||
uint64 uAmount)
|
STAmount saAmount)
|
||||||
{
|
{
|
||||||
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
|
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
|
||||||
naPublicKey, naSourceAccount,
|
naPublicKey, naSourceAccount,
|
||||||
uSeq, uFee, uSourceTag);
|
uSeq, saFee, uSourceTag);
|
||||||
|
|
||||||
return tResult->setPayment(naPrivateKey, toAccount, uAmount);
|
return tResult->setPayment(naPrivateKey, toAccount, saAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ private:
|
|||||||
Transaction::pointer setCreate(
|
Transaction::pointer setCreate(
|
||||||
const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& naCreateAccountID,
|
const NewcoinAddress& naCreateAccountID,
|
||||||
uint64 uFund);
|
STAmount uFund);
|
||||||
|
|
||||||
Transaction::pointer setPayment(
|
Transaction::pointer setPayment(
|
||||||
const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& toAccount,
|
const NewcoinAddress& toAccount,
|
||||||
uint64 uAmount);
|
STAmount saAmount);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Transaction(const SerializedTransaction::pointer st, bool bValidate);
|
Transaction(const SerializedTransaction::pointer st, bool bValidate);
|
||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
const NewcoinAddress& naPublicKey, // To prove transaction is consistent and authorized.
|
const NewcoinAddress& naPublicKey, // To prove transaction is consistent and authorized.
|
||||||
const NewcoinAddress& naSourceAccount, // To identify the paying account.
|
const NewcoinAddress& naSourceAccount, // To identify the paying account.
|
||||||
uint32 uSeq, // To order transactions.
|
uint32 uSeq, // To order transactions.
|
||||||
uint64 uFee, // Transaction fee.
|
STAmount saFee, // Transaction fee.
|
||||||
uint32 uSourceTag); // User call back value.
|
uint32 uSourceTag); // User call back value.
|
||||||
|
|
||||||
// Claim a wallet.
|
// Claim a wallet.
|
||||||
@@ -90,26 +90,20 @@ public:
|
|||||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& naSourceAccount,
|
const NewcoinAddress& naSourceAccount,
|
||||||
uint32 uSeq,
|
uint32 uSeq,
|
||||||
uint64 uFee,
|
STAmount saFee,
|
||||||
uint32 uSourceTag,
|
uint32 uSourceTag,
|
||||||
const NewcoinAddress& naCreateAccountID, // Account to create.
|
const NewcoinAddress& naCreateAccountID, // Account to create.
|
||||||
uint64 uFund); // Initial funds in XNC.
|
STAmount uFund); // Initial funds in XNC.
|
||||||
|
|
||||||
// Make a payment.
|
// Make a payment.
|
||||||
static Transaction::pointer sharedPayment(
|
static Transaction::pointer sharedPayment(
|
||||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||||
const NewcoinAddress& naSourceAccount,
|
const NewcoinAddress& naSourceAccount,
|
||||||
uint32 uSeq,
|
uint32 uSeq,
|
||||||
uint64 uFee,
|
STAmount saFee,
|
||||||
uint32 uSourceTag,
|
uint32 uSourceTag,
|
||||||
const NewcoinAddress& toAccount,
|
const NewcoinAddress& toAccount,
|
||||||
uint64 uAmount);
|
STAmount saAmount);
|
||||||
|
|
||||||
#if 0
|
|
||||||
Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toID,
|
|
||||||
CKey::pointer pubKey, uint64 uAmount, uint64 fee, uint32 fromSeq, uint32 fromLedger,
|
|
||||||
uint32 ident, const std::vector<unsigned char>& signature, uint32 ledgerSeq, TransStatus st);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool sign(const NewcoinAddress& naAccountPrivate);
|
bool sign(const NewcoinAddress& naAccountPrivate);
|
||||||
bool checkSign() const;
|
bool checkSign() const;
|
||||||
@@ -119,8 +113,8 @@ public:
|
|||||||
|
|
||||||
const uint256& getID() const { return mTransactionID; }
|
const uint256& getID() const { return mTransactionID; }
|
||||||
const NewcoinAddress& getFromAccount() const { return mAccountFrom; }
|
const NewcoinAddress& getFromAccount() const { return mAccountFrom; }
|
||||||
uint64 getAmount() const { return mTransaction->getITFieldU64(sfAmount); }
|
STAmount getAmount() const { return mTransaction->getITFieldU64(sfAmount); }
|
||||||
uint64 getFee() const { return mTransaction->getTransactionFee(); }
|
STAmount getFee() const { return mTransaction->getTransactionFee(); }
|
||||||
uint32 getFromAccountSeq() const { return mTransaction->getSequence(); }
|
uint32 getFromAccountSeq() const { return mTransaction->getSequence(); }
|
||||||
uint32 getSourceLedger() const { return mTransaction->getITFieldU32(sfTargetLedger); }
|
uint32 getSourceLedger() const { return mTransaction->getITFieldU32(sfTargetLedger); }
|
||||||
uint32 getIdent() const { return mTransaction->getITFieldU32(sfSourceTag); }
|
uint32 getIdent() const { return mTransaction->getITFieldU32(sfSourceTag); }
|
||||||
@@ -155,11 +149,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Transaction::pointer transactionFromSQL(const std::string& statement);
|
static Transaction::pointer transactionFromSQL(const std::string& statement);
|
||||||
#if 0
|
|
||||||
Transaction(const uint256& transactionID, const NewcoinAddress& accountFrom, const NewcoinAddress& accountTo,
|
|
||||||
CKey::pointer key, uint64 uAmount, uint64 fee, uint32 fromAccountSeq, uint32 sourceLedger,
|
|
||||||
uint32 ident, const std::vector<unsigned char>& signature, uint32 inLedger, TransStatus status);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -35,19 +35,19 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
return tenINVALID;
|
return tenINVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 uFee = theConfig.FEE_DEFAULT;
|
STAmount saCost = theConfig.FEE_DEFAULT;
|
||||||
|
|
||||||
// Customize behavoir based on transaction type.
|
// Customize behavoir based on transaction type.
|
||||||
switch(txn.getTxnType())
|
switch(txn.getTxnType())
|
||||||
{
|
{
|
||||||
case ttCLAIM:
|
case ttCLAIM:
|
||||||
uFee = 0;
|
saCost = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ttPAYMENT:
|
case ttPAYMENT:
|
||||||
if (txn.getFlags() & tfCreateAccount)
|
if (txn.getFlags() & tfCreateAccount)
|
||||||
{
|
{
|
||||||
uFee = theConfig.FEE_CREATE;
|
saCost = theConfig.FEE_CREATE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -70,13 +70,12 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
if (terSUCCESS != result)
|
if (terSUCCESS != result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
uint64 txnFee = txn.getTransactionFee();
|
STAmount saPaid = txn.getTransactionFee();
|
||||||
if ( (params & tepNO_CHECK_FEE) != tepNONE)
|
if ( (params & tepNO_CHECK_FEE) != tepNONE)
|
||||||
{
|
{
|
||||||
if (uFee)
|
if (saCost)
|
||||||
{
|
{
|
||||||
// WRITEME: Check if fee is adequate
|
if (saPaid < saCost)
|
||||||
if (txnFee == 0)
|
|
||||||
{
|
{
|
||||||
std::cerr << "applyTransaction: insufficient fee" << std::endl;
|
std::cerr << "applyTransaction: insufficient fee" << std::endl;
|
||||||
return tenINSUF_FEE_P;
|
return tenINSUF_FEE_P;
|
||||||
@@ -84,7 +83,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (txnFee)
|
if (!saPaid.isZero())
|
||||||
{
|
{
|
||||||
// Transaction is malformed.
|
// Transaction is malformed.
|
||||||
std::cerr << "applyTransaction: fee not allowed" << std::endl;
|
std::cerr << "applyTransaction: fee not allowed" << std::endl;
|
||||||
@@ -106,8 +105,8 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
// find source account
|
// find source account
|
||||||
// If we are only verifying some transactions, this would be probablistic.
|
// If we are only verifying some transactions, this would be probablistic.
|
||||||
LedgerStateParms qry = lepNONE;
|
LedgerStateParms qry = lepNONE;
|
||||||
SerializedLedgerEntry::pointer src = mLedger->getAccountRoot(qry, srcAccountID);
|
SerializedLedgerEntry::pointer sleSrc = mLedger->getAccountRoot(qry, srcAccountID);
|
||||||
if (!src)
|
if (!sleSrc)
|
||||||
{
|
{
|
||||||
std::cerr << str(boost::format("applyTransaction: Delay transaction: source account does not exisit: %s") % txn.getSourceAccount().humanAccountID()) << std::endl;
|
std::cerr << str(boost::format("applyTransaction: Delay transaction: source account does not exisit: %s") % txn.getSourceAccount().humanAccountID()) << std::endl;
|
||||||
return terNO_ACCOUNT;
|
return terNO_ACCOUNT;
|
||||||
@@ -115,25 +114,25 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
|
|
||||||
// deduct the fee, so it's not available during the transaction
|
// deduct the fee, so it's not available during the transaction
|
||||||
// we only write the account back if the transaction succeeds
|
// we only write the account back if the transaction succeeds
|
||||||
if (txnFee)
|
if (!saCost.isZero())
|
||||||
{
|
{
|
||||||
uint64 uSrcBalance = src->getIFieldU64(sfBalance);
|
STAmount saSrcBalance = sleSrc->getIValueFieldAmount(sfBalance);
|
||||||
|
|
||||||
if (uSrcBalance < txnFee)
|
if (saSrcBalance < saPaid)
|
||||||
{
|
{
|
||||||
std::cerr << "applyTransaction: Delay transaction: insufficent balance" << std::endl;
|
std::cerr << "applyTransaction: Delay transaction: insufficent balance" << std::endl;
|
||||||
return terINSUF_FEE_B;
|
return terINSUF_FEE_B;
|
||||||
}
|
}
|
||||||
|
|
||||||
src->setIFieldU64(sfBalance, uSrcBalance - txnFee);
|
sleSrc->setIFieldAmount(sfBalance, saSrcBalance - saPaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate sequence
|
// Validate sequence
|
||||||
uint32 t_seq = txn.getSequence();
|
uint32 t_seq = txn.getSequence();
|
||||||
|
|
||||||
if (uFee)
|
if (saCost)
|
||||||
{
|
{
|
||||||
uint32 a_seq = src->getIFieldU32(sfSequence);
|
uint32 a_seq = sleSrc->getIFieldU32(sfSequence);
|
||||||
|
|
||||||
if (t_seq != a_seq)
|
if (t_seq != a_seq)
|
||||||
{
|
{
|
||||||
@@ -152,7 +151,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
std::cerr << "applyTransaction: past sequence number" << std::endl;
|
std::cerr << "applyTransaction: past sequence number" << std::endl;
|
||||||
return terPAST_SEQ;
|
return terPAST_SEQ;
|
||||||
}
|
}
|
||||||
else src->setIFieldU32(sfSequence, t_seq);
|
else sleSrc->setIFieldU32(sfSequence, t_seq);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -164,7 +163,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<AffectedAccount> accounts;
|
std::vector<AffectedAccount> accounts;
|
||||||
accounts.push_back(std::make_pair(taaMODIFY, src));
|
accounts.push_back(std::make_pair(taaMODIFY, sleSrc));
|
||||||
|
|
||||||
switch(txn.getTxnType())
|
switch(txn.getTxnType())
|
||||||
{
|
{
|
||||||
@@ -219,7 +218,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
|
|
||||||
Serializer s;
|
Serializer s;
|
||||||
txn.add(s);
|
txn.add(s);
|
||||||
mLedger->addTransaction(txID, s, txnFee);
|
mLedger->addTransaction(txID, s, saPaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -384,20 +383,20 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction
|
|||||||
accounts.push_back(std::make_pair(taaMODIFY, dest));
|
accounts.push_back(std::make_pair(taaMODIFY, dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 uAmount = txn.getITFieldU64(sfAmount);
|
STAmount saAmount = txn.getITFieldAmount(sfAmount);
|
||||||
|
|
||||||
if (!currency)
|
if (!currency)
|
||||||
{
|
{
|
||||||
uint64 uSrcBalance = accounts[0].second->getIFieldU64(sfBalance);
|
STAmount saSrcBalance = accounts[0].second->getIValueFieldAmount(sfBalance);
|
||||||
|
|
||||||
if (uSrcBalance < uAmount)
|
if (saSrcBalance < saAmount)
|
||||||
{
|
{
|
||||||
std::cerr << "doPayment: Delay transaction: Insufficent funds." << std::endl;
|
std::cerr << "doPayment: Delay transaction: Insufficent funds." << std::endl;
|
||||||
return terUNFUNDED;
|
return terUNFUNDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts[0].second->setIFieldU64(sfBalance, uSrcBalance - uAmount);
|
accounts[0].second->setIFieldAmount(sfBalance, saSrcBalance - saAmount);
|
||||||
accounts[1].second->setIFieldU64(sfBalance, accounts[1].second->getIFieldU64(sfBalance) + uAmount);
|
accounts[1].second->setIFieldAmount(sfBalance, accounts[1].second->getIValueFieldAmount(sfBalance) + saAmount);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ TransactionFormat InnerTxnFormats[]=
|
|||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
|
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 2 },
|
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 2 },
|
||||||
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 4 },
|
|
||||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||||
},
|
},
|
||||||
|
|||||||
10
src/main.cpp
10
src/main.cpp
@@ -120,15 +120,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
else if (bTest)
|
else if (bTest)
|
||||||
{
|
{
|
||||||
std::vector<char*> pvCmd;
|
iResult = unit_test_main(init_unit_test, argc, argv);
|
||||||
|
|
||||||
// Copy all but "--test" at argv[1].
|
|
||||||
pvCmd.push_back(argv[0]);
|
|
||||||
|
|
||||||
for (int i=1; i++ != argc; )
|
|
||||||
pvCmd.push_back(argv[i]);
|
|
||||||
|
|
||||||
iResult = unit_test_main(init_unit_test, pvCmd.size()-1, &pvCmd[0]);
|
|
||||||
}
|
}
|
||||||
else if (!vm.count("parameters"))
|
else if (!vm.count("parameters"))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user