This commit is contained in:
jed
2012-09-05 15:33:48 -07:00
parent 6c7fadf479
commit 0d40390e6b
10 changed files with 132 additions and 11 deletions

View File

@@ -141,6 +141,7 @@
<ClCompile Include="src\RPCCommands.cpp" />
<ClCompile Include="src\RPCDoor.cpp" />
<ClCompile Include="src\RPCServer.cpp" />
<ClCompile Include="src\ScriptData.cpp" />
<ClCompile Include="src\SerializedLedger.cpp" />
<ClCompile Include="src\SerializedObject.cpp" />
<ClCompile Include="src\SerializedTransaction.cpp" />
@@ -232,6 +233,7 @@
<ClInclude Include="src\RPCDoor.h" />
<ClInclude Include="src\RPCServer.h" />
<ClInclude Include="src\ScopedLock.h" />
<ClInclude Include="src\ScriptData.h" />
<ClInclude Include="src\SecureAllocator.h" />
<ClInclude Include="src\SerializedLedger.h" />
<ClInclude Include="src\SerializedObject.h" />

View File

@@ -288,6 +288,9 @@
<ClCompile Include="src\Interpreter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ScriptData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="KnownNodeList.h">
@@ -533,8 +536,11 @@
<ClInclude Include="src\Contract.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ScriptData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Interpreter.h">
<Filter>Source Files</Filter>
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>

View File

@@ -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;

View File

@@ -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

View File

@@ -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,

View File

@@ -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<unsigned char> createCode = txn.getITFieldVL(sfCreateCode);
std::vector<unsigned char> fundCode = txn.getITFieldVL(sfFundCode);
std::vector<unsigned char> removeCode = txn.getITFieldVL(sfRemoveCode);
std::vector<unsigned char> 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

View File

@@ -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() { ; }

View File

@@ -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 }
};

View File

@@ -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

View File

@@ -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),