From da20c80697c8857db61823a16024919ddb5f6457 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 2 Jun 2012 14:25:08 -0700 Subject: [PATCH] Add support for creating AccountSet transactions. --- src/Transaction.cpp | 67 +++++++++++++++++++++++++++++++++++---------- src/Transaction.h | 21 ++++++++++++++ 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 1e2908496d..bea825cf4b 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -112,6 +112,53 @@ bool Transaction::sign(const NewcoinAddress& naAccountPrivate) return bResult; } +// +// AccountSet +// + +Transaction::pointer Transaction::setAccountSet( + const NewcoinAddress& naPrivateKey, + bool bUnsetEmailHash, + const uint128& uEmailHash, + bool bUnsetWalletLocator, + const uint256& uWalletLocator, + const std::vector& vucPubKey) +{ + mTransaction->setITFieldU32(sfFlags, + (bUnsetEmailHash ? tfUnsetEmailHash : 0) + | (bUnsetWalletLocator ? tfUnsetWalletLocator : 0)); + + if (!bUnsetEmailHash && !!uEmailHash) + mTransaction->setITFieldH128(sfEmailHash, uEmailHash); + + if (!bUnsetWalletLocator && !!uWalletLocator) + mTransaction->setITFieldH256(sfWalletLocator, uWalletLocator); + + if (!vucPubKey.empty()) + mTransaction->setITFieldVL(sfMessageKey, vucPubKey); + + sign(naPrivateKey); + + return shared_from_this(); +} + +Transaction::pointer Transaction::sharedAccountSet( + const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naSourceAccount, + uint32 uSeq, + const STAmount& saFee, + uint32 uSourceTag, + bool bUnsetEmailHash, + const uint128& uEmailHash, + bool bUnsetWalletLocator, + const uint256& uWalletLocator, + const std::vector& vucPubKey) +{ + pointer tResult = boost::make_shared(ttACCOUNT_SET, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); + + return tResult->setAccountSet(naPrivateKey, bUnsetEmailHash, uEmailHash, bUnsetWalletLocator, uWalletLocator, vucPubKey); +} + // // Claim // @@ -175,9 +222,7 @@ Transaction::pointer Transaction::sharedCreate( const NewcoinAddress& naCreateAccountID, const STAmount& saFund) { - pointer tResult = boost::make_shared(ttPAYMENT, - naPublicKey, naSourceAccount, - uSeq, saFee, uSourceTag); + pointer tResult = boost::make_shared(ttPAYMENT, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); return tResult->setCreate(naPrivateKey, naCreateAccountID, saFund); } @@ -212,9 +257,7 @@ Transaction::pointer Transaction::sharedCreditSet( const STAmount& saLimitAmount, uint32 uAcceptRate) { - pointer tResult = boost::make_shared(ttCREDIT_SET, - naPublicKey, naSourceAccount, - uSeq, saFee, uSourceTag); + pointer tResult = boost::make_shared(ttCREDIT_SET, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); return tResult->setCreditSet(naPrivateKey, naDstAccountID, saLimitAmount, uAcceptRate); } @@ -259,9 +302,7 @@ Transaction::pointer Transaction::sharedPayment( const STAmount& saSendMax, const STPathSet& saPaths) { - pointer tResult = boost::make_shared(ttPAYMENT, - naPublicKey, naSourceAccount, - uSeq, saFee, uSourceTag); + pointer tResult = boost::make_shared(ttPAYMENT, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); return tResult->setPayment(naPrivateKey, naDstAccountID, saAmount, saSendMax, saPaths); } @@ -298,9 +339,7 @@ Transaction::pointer Transaction::sharedTransitSet( uint32 uTransitStart, uint32 uTransitExpire) { - pointer tResult = boost::make_shared(ttTRANSIT_SET, - naPublicKey, naSourceAccount, - uSeq, saFee, uSourceTag); + pointer tResult = boost::make_shared(ttTRANSIT_SET, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); return tResult->setTransitSet(naPrivateKey, uTransitRate, uTransitStart, uTransitExpire); } @@ -337,9 +376,7 @@ Transaction::pointer Transaction::sharedWalletAdd( const NewcoinAddress& naNewPubKey, const std::vector& vucSignature) { - pointer tResult = boost::make_shared(ttWALLET_ADD, - naPublicKey, naSourceAccount, - uSeq, saFee, uSourceTag); + pointer tResult = boost::make_shared(ttWALLET_ADD, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); return tResult->setWalletAdd(naPrivateKey, saAmount, naAuthKeyID, naNewPubKey, vucSignature); } diff --git a/src/Transaction.h b/src/Transaction.h index 9a28f5b283..a0eb1a12ae 100644 --- a/src/Transaction.h +++ b/src/Transaction.h @@ -46,6 +46,14 @@ private: SerializedTransaction::pointer mTransaction; + Transaction::pointer setAccountSet( + const NewcoinAddress& naPrivateKey, + bool bUnsetEmailHash, + const uint128& uEmailHash, + bool bUnsetWalletLocator, + const uint256& uWalletLocator, + const std::vector& vucPubKey); + Transaction::pointer setClaim( const NewcoinAddress& naPrivateKey, const std::vector& vucGenerator, @@ -96,6 +104,19 @@ public: const STAmount& saFee, // Transaction fee. uint32 uSourceTag); // User call back value. + // Change account settings. + static Transaction::pointer sharedAccountSet( + const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey, + const NewcoinAddress& naSourceAccount, + uint32 uSeq, + const STAmount& saFee, + uint32 uSourceTag, + bool bUnsetEmailHash, + const uint128& uEmailHash, + bool bUnsetWalletLocator, + const uint256& uWalletLocator, + const std::vector& vucPubKey); + // Claim a wallet. static Transaction::pointer sharedClaim( const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,