diff --git a/src/Transaction.cpp b/src/Transaction.cpp index d60939eb5b..5872fdbf27 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -155,11 +155,11 @@ Transaction::pointer Transaction::sharedClaim( Transaction::pointer Transaction::setCreate( const NewcoinAddress& naPrivateKey, const NewcoinAddress& naCreateAccountID, - const STAmount& uFund) + const STAmount& saFund) { mTransaction->setITFieldU32(sfFlags, tfCreateAccount); mTransaction->setITFieldAccount(sfDestination, naCreateAccountID); - mTransaction->setITFieldAmount(sfAmount, uFund); + mTransaction->setITFieldAmount(sfAmount, saFund); sign(naPrivateKey); @@ -173,13 +173,58 @@ Transaction::pointer Transaction::sharedCreate( const STAmount& saFee, uint32 uSourceTag, const NewcoinAddress& naCreateAccountID, - const STAmount& uFund) + const STAmount& saFund) { pointer tResult = boost::make_shared(ttPAYMENT, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); - return tResult->setCreate(naPrivateKey, naCreateAccountID, uFund); + return tResult->setCreate(naPrivateKey, naCreateAccountID, saFund); +} + +// +// CreditSet +// + +Transaction::pointer Transaction::setCreditSet( + const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naDstAccountID, + const STAmount& saLimitAmount, + uint32 uBorrowRate, + uint32 uBorrowStart, + uint32 uBorrowExpire) +{ + mTransaction->setITFieldAccount(sfDestination, naDstAccountID); + mTransaction->setITFieldAmount(sfLimitAmount, saLimitAmount); + if (uBorrowRate) + mTransaction->setITFieldU32(sfBorrowRate, uBorrowRate); + if (uBorrowStart) + mTransaction->setITFieldU32(sfBorrowStart, uBorrowStart); + if (uBorrowExpire) + mTransaction->setITFieldU32(sfBorrowExpire, uBorrowExpire); + + sign(naPrivateKey); + + return shared_from_this(); +} + +Transaction::pointer Transaction::sharedCreditSet( + const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naSourceAccount, + uint32 uSeq, + const STAmount& saFee, + uint32 uSourceTag, + const NewcoinAddress& naDstAccountID, + const STAmount& saLimitAmount, + uint32 uBorrowRate, + uint32 uBorrowStart, + uint32 uBorrowExpire) +{ + pointer tResult = boost::make_shared(ttCREDIT_SET, + naPublicKey, naSourceAccount, + uSeq, saFee, uSourceTag); + + return tResult->setCreditSet(naPrivateKey, naDstAccountID, saLimitAmount, uBorrowRate, uBorrowStart, uBorrowExpire); } // @@ -188,12 +233,12 @@ Transaction::pointer Transaction::sharedCreate( Transaction::pointer Transaction::setPayment( const NewcoinAddress& naPrivateKey, - const NewcoinAddress& toAccount, + const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, const STPathSet& spPaths) { - mTransaction->setITFieldAccount(sfDestination, toAccount); + mTransaction->setITFieldAccount(sfDestination, naDstAccountID); mTransaction->setITFieldAmount(sfAmount, saAmount); if (saAmount != saSendMax) @@ -217,7 +262,7 @@ Transaction::pointer Transaction::sharedPayment( uint32 uSeq, const STAmount& saFee, uint32 uSourceTag, - const NewcoinAddress& toAccount, + const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, const STPathSet& saPaths) @@ -226,7 +271,46 @@ Transaction::pointer Transaction::sharedPayment( naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); - return tResult->setPayment(naPrivateKey, toAccount, saAmount, saSendMax, saPaths); + return tResult->setPayment(naPrivateKey, naDstAccountID, saAmount, saSendMax, saPaths); +} + +// +// TransitSet +// + +Transaction::pointer Transaction::setTransitSet( + const NewcoinAddress& naPrivateKey, + uint32 uTransitRate, + uint32 uTransitStart, + uint32 uTransitExpire) +{ + if (uTransitRate) + mTransaction->setITFieldU32(sfTransitRate, uTransitRate); + if (uTransitStart) + mTransaction->setITFieldU32(sfTransitStart, uTransitStart); + if (uTransitExpire) + mTransaction->setITFieldU32(sfTransitExpire, uTransitExpire); + + sign(naPrivateKey); + + return shared_from_this(); +} + +Transaction::pointer Transaction::sharedTransitSet( + const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naSourceAccount, + uint32 uSeq, + const STAmount& saFee, + uint32 uSourceTag, + uint32 uTransitRate, + uint32 uTransitStart, + uint32 uTransitExpire) +{ + pointer tResult = boost::make_shared(ttTRANSIT_SET, + naPublicKey, naSourceAccount, + uSeq, saFee, uSourceTag); + + return tResult->setTransitSet(naPrivateKey, uTransitRate, uTransitStart, uTransitExpire); } // diff --git a/src/Transaction.h b/src/Transaction.h index 475f5faac4..e148270468 100644 --- a/src/Transaction.h +++ b/src/Transaction.h @@ -55,15 +55,29 @@ private: Transaction::pointer setCreate( const NewcoinAddress& naPrivateKey, const NewcoinAddress& naCreateAccountID, - const STAmount& uFund); + const STAmount& saFund); + + Transaction::pointer setCreditSet( + const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naDstAccountID, + const STAmount& saLimitAmount, + uint32 uBorrowRate, + uint32 uBorrowStart, + uint32 uBorrowExpire); Transaction::pointer setPayment( const NewcoinAddress& naPrivateKey, - const NewcoinAddress& toAccount, + const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, const STPathSet& spPaths); + Transaction::pointer setTransitSet( + const NewcoinAddress& naPrivateKey, + uint32 uTransitRate, + uint32 uTransitStart, + uint32 uTransitExpire); + public: Transaction(const SerializedTransaction::pointer st, bool bValidate); @@ -94,7 +108,20 @@ public: const STAmount& saFee, uint32 uSourceTag, const NewcoinAddress& naCreateAccountID, // Account to create. - const STAmount& uFund); // Initial funds in XNC. + const STAmount& saFund); // Initial funds in XNC. + + // Set credit limit and borrow fees. + static Transaction::pointer sharedCreditSet( + const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naSourceAccount, + uint32 uSeq, + const STAmount& saFee, + uint32 uSourceTag, + const NewcoinAddress& naDstAccountID, + const STAmount& saLimitAmount, + uint32 uBorrowRate, + uint32 uBorrowStart, + uint32 uBorrowExpire); // Make a payment. static Transaction::pointer sharedPayment( @@ -103,11 +130,22 @@ public: uint32 uSeq, const STAmount& saFee, uint32 uSourceTag, - const NewcoinAddress& toAccount, + const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, const STPathSet& saPaths); + // Set transit fees. + static Transaction::pointer sharedTransitSet( + const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naSourceAccount, + uint32 uSeq, + const STAmount& saFee, + uint32 uSourceTag, + uint32 uTransitRate, + uint32 uTransitStart, + uint32 uTransitExpire); + bool sign(const NewcoinAddress& naAccountPrivate); bool checkSign() const; void updateID() { mTransactionID=mTransaction->getTransactionID(); }