diff --git a/newcoin.vcxproj b/newcoin.vcxproj
index adb8abc714..6f7548d105 100644
--- a/newcoin.vcxproj
+++ b/newcoin.vcxproj
@@ -141,6 +141,7 @@
+
@@ -232,6 +233,7 @@
+
diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters
index b97a607c9e..fcf37fc266 100644
--- a/newcoin.vcxproj.filters
+++ b/newcoin.vcxproj.filters
@@ -288,6 +288,9 @@
Source Files
+
+ Source Files
+
@@ -533,8 +536,11 @@
Header Files
+
+ Header Files
+
- Source Files
+ Header Files
diff --git a/src/LedgerFormats.cpp b/src/LedgerFormats.cpp
index a5662004e7..e1376ea3af 100644
--- a/src/LedgerFormats.cpp
+++ b/src/LedgerFormats.cpp
@@ -77,9 +77,25 @@ LedgerEntryFormat LedgerFormats[]=
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
+ { "Contract", ltCONTRACT, {
+ { S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
+ { S_FIELD(Issuer), STI_ACCOUNT, SOE_REQUIRED, 0 },
+ { S_FIELD(Owner), STI_ACCOUNT, SOE_REQUIRED, 0 },
+ { S_FIELD(Expiration), STI_UINT32, SOE_REQUIRED, 0 },
+ { S_FIELD(BondAmount), STI_UINT32, SOE_REQUIRED, 0 },
+ { S_FIELD(StampEscrow), STI_UINT32, SOE_REQUIRED, 0 },
+ { S_FIELD(RippleEscrow), STI_AMOUNT, SOE_REQUIRED, 0 },
+ { S_FIELD(CreateCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(FundCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(RemoveCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(ExpireCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
+ { sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
+ },
{ NULL, ltINVALID }
};
+
LedgerEntryFormat* getLgrFormat(LedgerEntryType t)
{
LedgerEntryFormat* f = LedgerFormats;
diff --git a/src/LedgerFormats.h b/src/LedgerFormats.h
index 22ae55ebf2..c1cdc505b6 100644
--- a/src/LedgerFormats.h
+++ b/src/LedgerFormats.h
@@ -13,6 +13,7 @@ enum LedgerEntryType
ltRIPPLE_STATE = 'r',
ltNICKNAME = 'n',
ltOFFER = 'o',
+ ltCONTRACT = 'c',
};
// Used as a prefix for computing ledger indexes (keys).
@@ -26,8 +27,7 @@ enum LedgerNameSpace
spaceOffer = 'o', // Entry for an offer.
spaceOwnerDir = 'O', // Directory of things owned by an account.
spaceBookDir = 'B', // Directory of order books.
- spaceBond = 'b',
- spaceInvoice = 'i',
+ spaceContract = 'c',
};
enum LedgerSpecificFlags
diff --git a/src/SerializedObject.h b/src/SerializedObject.h
index d53dd5ed12..3e36c07c9f 100644
--- a/src/SerializedObject.h
+++ b/src/SerializedObject.h
@@ -18,6 +18,8 @@ enum SOE_Type
SOE_IFNFLAG = 3 // present if flag not set
};
+// JED: seems like there would be a better way to do this
+// maybe something that inherits from SerializedTransaction
enum SOE_Field
{
sfInvalid = -1,
@@ -31,12 +33,14 @@ enum SOE_Field
sfAmount,
sfAuthorizedKey,
sfBalance,
+ sfBondAmount,
sfBookDirectory,
sfBookNode,
sfBorrowExpire,
sfBorrowRate,
sfBorrowStart,
sfBorrower,
+ sfCreateCode,
sfCloseTime,
sfCurrency,
sfCurrencyIn,
@@ -45,9 +49,11 @@ enum SOE_Field
sfDomain,
sfEmailHash,
sfExpiration,
+ sfExpireCode,
sfExtensions,
sfFirstNode,
sfFlags,
+ sfFundCode,
sfGenerator,
sfGeneratorID,
sfHash,
@@ -60,6 +66,7 @@ enum SOE_Field
sfIndexNext,
sfIndexPrevious,
sfInvoiceID,
+ sfIssuer,
sfLastNode,
sfLastReceive,
sfLastSignedSeq,
@@ -81,6 +88,7 @@ enum SOE_Field
sfNextTransitStart,
sfNickname,
sfOfferSequence,
+ sfOwner,
sfOwnerNode,
sfPaths,
sfPubKey,
@@ -88,12 +96,15 @@ enum SOE_Field
sfPublishSize,
sfQualityIn,
sfQualityOut,
+ sfRemoveCode,
+ sfRippleEscrow,
sfSendMax,
sfSequence,
sfSignature,
sfSigningKey,
sfSigningTime,
sfSourceTag,
+ sfStampEscrow,
sfTakerGets,
sfTakerPays,
sfTarget,
diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp
index aa58296949..7bc875e06e 100644
--- a/src/TransactionEngine.cpp
+++ b/src/TransactionEngine.cpp
@@ -996,7 +996,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
STAmount saCost = theConfig.FEE_DEFAULT;
- // Customize behavoir based on transaction type.
+ // Customize behavior based on transaction type.
if (tesSUCCESS == terResult)
{
switch (txn.getTxnType())
@@ -1024,7 +1024,6 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
case ttACCOUNT_SET:
case ttCREDIT_SET:
- case ttINVOICE:
case ttOFFER_CREATE:
case ttOFFER_CANCEL:
case ttPASSWORD_FUND:
@@ -1194,7 +1193,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
else if (saSrcBalance < saPaid)
{
Log(lsINFO)
- << boost::str(boost::format("applyTransaction: Delay: insufficent balance: balance=%s paid=%s")
+ << boost::str(boost::format("applyTransaction: Delay: insufficient balance: balance=%s paid=%s")
% saSrcBalance.getText()
% saPaid.getText());
@@ -1278,9 +1277,9 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
terResult = temINVALID;
break;
- case ttINVOICE:
- terResult = doInvoice(txn);
- break;
+ //case ttINVOICE:
+ // terResult = doInvoice(txn);
+ // break;
case ttOFFER_CREATE:
terResult = doOfferCreate(txn);
@@ -1310,6 +1309,13 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
terResult = doWalletAdd(txn);
break;
+ case ttCONTRACT:
+ terResult= doContractAdd(txn);
+ break;
+ case ttCONTRACT_REMOVE:
+ terResult=doContractRemove(txn);
+ break;
+
default:
terResult = temUNKNOWN;
break;
@@ -1358,6 +1364,8 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
return terResult;
}
+
+
TER TransactionEngine::doAccountSet(const SerializedTransaction& txn)
{
Log(lsINFO) << "doAccountSet>";
@@ -4757,4 +4765,53 @@ TER TransactionEngine::doDelete(const SerializedTransaction& txn)
return temUNKNOWN;
}
+#include "Interpreter.h"
+#include "Contract.h"
+
+TER TransactionEngine::doContractAdd(const SerializedTransaction& txn)
+{
+ Log(lsWARNING) << "doContractAdd> " << txn.getJson(0);
+
+ const uint32 expiration = txn.getITFieldU32(sfExpiration);
+ const uint32 bondAmount = txn.getITFieldU32(sfBondAmount);
+ const uint32 stampEscrow = txn.getITFieldU32(sfStampEscrow);
+ STAmount rippleEscrow = txn.getITFieldAmount(sfRippleEscrow);
+ std::vector createCode = txn.getITFieldVL(sfCreateCode);
+ std::vector fundCode = txn.getITFieldVL(sfFundCode);
+ std::vector removeCode = txn.getITFieldVL(sfRemoveCode);
+ std::vector expireCode = txn.getITFieldVL(sfExpireCode);
+
+ // make sure
+ // expiration hasn't passed
+ // bond amount is enough
+ // they have the stamps for the bond
+
+ // place contract in ledger
+ // run create code
+
+
+ if (mLedger->getParentCloseTimeNC() >= expiration)
+ {
+ Log(lsWARNING) << "doContractAdd: Expired transaction: offer expired";
+ return(tefALREADY);
+ }
+ //TODO: check bond
+ //if( txn.getSourceAccount() )
+
+ Contract contract;
+ Interpreter interpreter;
+ TER terResult=interpreter->interpret(&contract,txn,createCode);
+ if(tesSUCCESS != terResult)
+ {
+
+ }
+
+ return(terResult);
+}
+
+TER TransactionEngine::doContractRemove(const SerializedTransaction& txn)
+{
+
+}
+
// vim:ts=4
diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h
index 9747850e6b..364e69de34 100644
--- a/src/TransactionEngine.h
+++ b/src/TransactionEngine.h
@@ -63,7 +63,7 @@ enum TER // aka TransactionEngineResult
// Implications:
// - Not applied
// - Not forwarded
- // - Could succeed in an imaginared ledger.
+ // - Could succeed in an imagined ledger.
tefFAILURE = -199,
tefALREADY,
tefBAD_ADD_AUTH,
@@ -334,6 +334,8 @@ protected:
TER doStore(const SerializedTransaction& txn);
TER doTake(const SerializedTransaction& txn);
TER doWalletAdd(const SerializedTransaction& txn);
+ TER doContractAdd(const SerializedTransaction& txn);
+ TER doContractRemove(const SerializedTransaction& txn);
public:
TransactionEngine() { ; }
diff --git a/src/TransactionFormats.cpp b/src/TransactionFormats.cpp
index 00318027b2..5260b6bb66 100644
--- a/src/TransactionFormats.cpp
+++ b/src/TransactionFormats.cpp
@@ -37,6 +37,7 @@ TransactionFormat InnerTxnFormats[]=
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
+ /*
{ "Invoice", ttINVOICE, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(Target), STI_ACCOUNT, SOE_REQUIRED, 0 },
@@ -47,6 +48,7 @@ TransactionFormat InnerTxnFormats[]=
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
+ */
{ "NicknameSet", ttNICKNAME_SET, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(Nickname), STI_HASH256, SOE_REQUIRED, 0 },
@@ -110,6 +112,25 @@ TransactionFormat InnerTxnFormats[]=
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
+ { "Contract", ttCONTRACT, {
+ { S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
+ { S_FIELD(Expiration), STI_UINT32, SOE_REQUIRED, 0 },
+ { S_FIELD(BondAmount), STI_UINT32, SOE_REQUIRED, 0 },
+ { S_FIELD(StampEscrow), STI_UINT32, SOE_REQUIRED, 0 },
+ { S_FIELD(RippleEscrow), STI_AMOUNT, SOE_REQUIRED, 0 },
+ { S_FIELD(CreateCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(FundCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(RemoveCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(ExpireCode), STI_VL, SOE_REQUIRED, 0 },
+ { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
+ { sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
+ },
+ { "Contract", ttCONTRACT_REMOVE, {
+ { S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
+ { S_FIELD(ContractID), STI_ACCOUNT, SOE_REQUIRED, 0 },
+ { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
+ { sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
+ },
{ NULL, ttINVALID }
};
diff --git a/src/TransactionFormats.h b/src/TransactionFormats.h
index a49a1513e1..a77fcd3ad0 100644
--- a/src/TransactionFormats.h
+++ b/src/TransactionFormats.h
@@ -15,8 +15,10 @@ enum TransactionType
ttNICKNAME_SET = 6,
ttOFFER_CREATE = 7,
ttOFFER_CANCEL = 8,
+ ttCONTRACT = 9,
+ ttCONTRACT_REMOVE = 10, // can we use the same msg as offer cancel
+
ttCREDIT_SET = 20,
- ttINVOICE = 10,
};
struct TransactionFormat
diff --git a/src/UniqueNodeList.cpp b/src/UniqueNodeList.cpp
index 74ceb647fd..708a4f5e94 100644
--- a/src/UniqueNodeList.cpp
+++ b/src/UniqueNodeList.cpp
@@ -39,6 +39,10 @@
#define REFERRAL_VALIDATORS_MAX 50
#define REFERRAL_IPS_MAX 50
+#ifndef MIN
+#define MIN(x,y) ((x)<(y)?(x):(y))
+#endif
+
UniqueNodeList::UniqueNodeList(boost::asio::io_service& io_service) :
mdtScoreTimer(io_service),
mFetchActive(0),