View
@@ -1,264 +0,0 @@
-// Copyright (c) 2009 Satoshi Nakamoto
-// Distributed under the MIT/X11 software license, see the accompanying
-// file license.txt or http://www.opensource.org/licenses/mit-license.php.
-
-#include "headers.h"
-
-
-
-
-
-
-
-
-
-
-//
-// Global state variables
-//
-
-//// later figure out how these are persisted
-map<uint256, CProduct> mapMyProducts;
-
-
-
-
-map<uint256, CProduct> mapProducts;
-CCriticalSection cs_mapProducts;
-
-bool AdvertInsert(const CProduct& product)
-{
- uint256 hash = product.GetHash();
- bool fNew = false;
- bool fUpdated = false;
-
- CRITICAL_BLOCK(cs_mapProducts)
- {
- // Insert or find existing product
- pair<map<uint256, CProduct>::iterator, bool> item = mapProducts.insert(make_pair(hash, product));
- CProduct* pproduct = &(*(item.first)).second;
- fNew = item.second;
-
- // Update if newer
- if (product.nSequence > pproduct->nSequence)
- {
- *pproduct = product;
- fUpdated = true;
- }
- }
-
- //if (fNew)
- // NotifyProductAdded(hash);
- //else if (fUpdated)
- // NotifyProductUpdated(hash);
-
- return (fNew || fUpdated);
-}
-
-void AdvertErase(const CProduct& product)
-{
- uint256 hash = product.GetHash();
- CRITICAL_BLOCK(cs_mapProducts)
- mapProducts.erase(hash);
- //NotifyProductDeleted(hash);
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-template<typename T>
-unsigned int Union(T& v1, T& v2)
-{
- // v1 = v1 union v2
- // v1 and v2 must be sorted
- // returns the number of elements added to v1
-
- ///// need to check that this is equivalent, then delete this comment
- //vector<unsigned short> vUnion(v1.size() + v2.size());
- //vUnion.erase(set_union(v1.begin(), v1.end(),
- // v2.begin(), v2.end(),
- // vUnion.begin()),
- // vUnion.end());
-
- T vUnion;
- vUnion.reserve(v1.size() + v2.size());
- set_union(v1.begin(), v1.end(),
- v2.begin(), v2.end(),
- back_inserter(vUnion));
- unsigned int nAdded = vUnion.size() - v1.size();
- if (nAdded > 0)
- v1 = vUnion;
- return nAdded;
-}
-
-void CUser::AddAtom(unsigned short nAtom, bool fOrigin)
-{
- // Ignore duplicates
- if (binary_search(vAtomsIn.begin(), vAtomsIn.end(), nAtom) ||
- find(vAtomsNew.begin(), vAtomsNew.end(), nAtom) != vAtomsNew.end())
- return;
-
- //// instead of zero atom, should change to free atom that propagates,
- //// limited to lower than a certain value like 5 so conflicts quickly
- // The zero atom never propagates,
- // new atoms always propagate through the user that created them
- if (nAtom == 0 || fOrigin)
- {
- vector<unsigned short> vTmp(1, nAtom);
- Union(vAtomsIn, vTmp);
- if (fOrigin)
- vAtomsOut.push_back(nAtom);
- return;
- }
-
- vAtomsNew.push_back(nAtom);
-
- if (vAtomsNew.size() >= nFlowthroughRate || vAtomsOut.empty())
- {
- // Select atom to flow through to vAtomsOut
- vAtomsOut.push_back(vAtomsNew[GetRand(vAtomsNew.size())]);
-
- // Merge vAtomsNew into vAtomsIn
- sort(vAtomsNew.begin(), vAtomsNew.end());
- Union(vAtomsIn, vAtomsNew);
- vAtomsNew.clear();
- }
-}
-
-bool AddAtomsAndPropagate(uint256 hashUserStart, const vector<unsigned short>& vAtoms, bool fOrigin)
-{
- CReviewDB reviewdb;
- map<uint256, vector<unsigned short> > pmapPropagate[2];
- pmapPropagate[0][hashUserStart] = vAtoms;
-
- for (int side = 0; !pmapPropagate[side].empty(); side = 1 - side)
- {
- map<uint256, vector<unsigned short> >& mapFrom = pmapPropagate[side];
- map<uint256, vector<unsigned short> >& mapTo = pmapPropagate[1 - side];
-
- for (map<uint256, vector<unsigned short> >::iterator mi = mapFrom.begin(); mi != mapFrom.end(); ++mi)
- {
- const uint256& hashUser = (*mi).first;
- const vector<unsigned short>& vReceived = (*mi).second;
-
- ///// this would be a lot easier on the database if it put the new atom at the beginning of the list,
- ///// so the change would be right next to the vector size.
-
- // Read user
- CUser user;
- reviewdb.ReadUser(hashUser, user);
- unsigned int nIn = user.vAtomsIn.size();
- unsigned int nNew = user.vAtomsNew.size();
- unsigned int nOut = user.vAtomsOut.size();
-
- // Add atoms received
- foreach(unsigned short nAtom, vReceived)
- user.AddAtom(nAtom, fOrigin);
- fOrigin = false;
-
- // Don't bother writing to disk if no changes
- if (user.vAtomsIn.size() == nIn && user.vAtomsNew.size() == nNew)
- continue;
-
- // Propagate
- if (user.vAtomsOut.size() > nOut)
- foreach(const uint256& hash, user.vLinksOut)
- mapTo[hash].insert(mapTo[hash].end(), user.vAtomsOut.begin() + nOut, user.vAtomsOut.end());
-
- // Write back
- if (!reviewdb.WriteUser(hashUser, user))
- return false;
- }
- mapFrom.clear();
- }
- return true;
-}
-
-
-
-
-
-
-bool CReview::AcceptReview()
-{
- // Timestamp
- nTime = GetTime();
-
- // Check signature
- if (!CKey::Verify(vchPubKeyFrom, GetSigHash(), vchSig))
- return false;
-
- CReviewDB reviewdb;
-
- // Add review text to recipient
- vector<CReview> vReviews;
- reviewdb.ReadReviews(hashTo, vReviews);
- vReviews.push_back(*this);
- if (!reviewdb.WriteReviews(hashTo, vReviews))
- return false;
-
- // Add link from sender
- CUser user;
- uint256 hashFrom = Hash(vchPubKeyFrom.begin(), vchPubKeyFrom.end());
- reviewdb.ReadUser(hashFrom, user);
- user.vLinksOut.push_back(hashTo);
- if (!reviewdb.WriteUser(hashFrom, user))
- return false;
-
- reviewdb.Close();
-
- // Propagate atoms to recipient
- vector<unsigned short> vZeroAtom(1, 0);
- if (!AddAtomsAndPropagate(hashTo, user.vAtomsOut.size() ? user.vAtomsOut : vZeroAtom, false))
- return false;
-
- return true;
-}
-
-
-
-
-
-bool CProduct::CheckSignature()
-{
- return (CKey::Verify(vchPubKeyFrom, GetSigHash(), vchSig));
-}
-
-bool CProduct::CheckProduct()
-{
- if (!CheckSignature())
- return false;
-
- // Make sure it's a summary product
- if (!mapDetails.empty() || !vOrderForm.empty())
- return false;
-
- // Look up seller's atom count
- CReviewDB reviewdb("r");
- CUser user;
- reviewdb.ReadUser(GetUserHash(), user);
- nAtoms = user.GetAtomCount();
- reviewdb.Close();
-
- ////// delme, this is now done by AdvertInsert
- //// Store to memory
- //CRITICAL_BLOCK(cs_mapProducts)
- // mapProducts[GetHash()] = *this;
-
- return true;
-}
View
182 market.h
@@ -1,182 +0,0 @@
-// Copyright (c) 2009 Satoshi Nakamoto
-// Distributed under the MIT/X11 software license, see the accompanying
-// file license.txt or http://www.opensource.org/licenses/mit-license.php.
-
-class CUser;
-class CReview;
-class CProduct;
-
-static const unsigned int nFlowthroughRate = 2;
-
-
-
-
-bool AdvertInsert(const CProduct& product);
-void AdvertErase(const CProduct& product);
-bool AddAtomsAndPropagate(uint256 hashUserStart, const vector<unsigned short>& vAtoms, bool fOrigin);
-
-
-
-
-
-
-
-
-class CUser
-{
-public:
- vector<unsigned short> vAtomsIn;
- vector<unsigned short> vAtomsNew;
- vector<unsigned short> vAtomsOut;
- vector<uint256> vLinksOut;
-
- CUser()
- {
- }
-
- IMPLEMENT_SERIALIZE
- (
- if (!(nType & SER_GETHASH))
- READWRITE(nVersion);
- READWRITE(vAtomsIn);
- READWRITE(vAtomsNew);
- READWRITE(vAtomsOut);
- READWRITE(vLinksOut);
- )
-
- void SetNull()
- {
- vAtomsIn.clear();
- vAtomsNew.clear();
- vAtomsOut.clear();
- vLinksOut.clear();
- }
-
- uint256 GetHash() const { return SerializeHash(*this); }
-
-
- int GetAtomCount() const
- {
- return (vAtomsIn.size() + vAtomsNew.size());
- }
-
- void AddAtom(unsigned short nAtom, bool fOrigin);
-};
-
-
-
-
-
-
-
-class CReview
-{
-public:
- int nVersion;
- uint256 hashTo;
- map<string, string> mapValue;
- vector<unsigned char> vchPubKeyFrom;
- vector<unsigned char> vchSig;
-
- // memory only
- unsigned int nTime;
- int nAtoms;
-
-
- CReview()
- {
- nVersion = 1;
- hashTo = 0;
- nTime = 0;
- nAtoms = 0;
- }
-
- IMPLEMENT_SERIALIZE
- (
- READWRITE(this->nVersion);
- nVersion = this->nVersion;
- if (!(nType & SER_DISK))
- READWRITE(hashTo);
- READWRITE(mapValue);
- READWRITE(vchPubKeyFrom);
- if (!(nType & SER_GETHASH))
- READWRITE(vchSig);
- )
-
- uint256 GetHash() const { return SerializeHash(*this); }
- uint256 GetSigHash() const { return SerializeHash(*this, SER_GETHASH|SER_SKIPSIG); }
- uint256 GetUserHash() const { return Hash(vchPubKeyFrom.begin(), vchPubKeyFrom.end()); }
-
-
- bool AcceptReview();
-};
-
-
-
-
-
-
-
-class CProduct
-{
-public:
- int nVersion;
- CAddress addr;
- map<string, string> mapValue;
- map<string, string> mapDetails;
- vector<pair<string, string> > vOrderForm;
- unsigned int nSequence;
- vector<unsigned char> vchPubKeyFrom;
- vector<unsigned char> vchSig;
-
- // disk only
- int nAtoms;
-
- // memory only
- set<unsigned int> setSources;
-
- CProduct()
- {
- nVersion = 1;
- nAtoms = 0;
- nSequence = 0;
- }
-
- IMPLEMENT_SERIALIZE
- (
- READWRITE(this->nVersion);
- nVersion = this->nVersion;
- READWRITE(addr);
- READWRITE(mapValue);
- if (!(nType & SER_GETHASH))
- {
- READWRITE(mapDetails);
- READWRITE(vOrderForm);
- READWRITE(nSequence);
- }
- READWRITE(vchPubKeyFrom);
- if (!(nType & SER_GETHASH))
- READWRITE(vchSig);
- if (nType & SER_DISK)
- READWRITE(nAtoms);
- )
-
- uint256 GetHash() const { return SerializeHash(*this); }
- uint256 GetSigHash() const { return SerializeHash(*this, SER_GETHASH|SER_SKIPSIG); }
- uint256 GetUserHash() const { return Hash(vchPubKeyFrom.begin(), vchPubKeyFrom.end()); }
-
-
- bool CheckSignature();
- bool CheckProduct();
-};
-
-
-
-
-
-
-
-
-extern map<uint256, CProduct> mapProducts;
-extern CCriticalSection cs_mapProducts;
-extern map<uint256, CProduct> mapMyProducts;
View
@@ -381,11 +381,6 @@ void CNode::CancelSubscribe(unsigned int nChannel)
foreach(CNode* pnode, vNodes)
if (pnode != this)
pnode->PushMessage("sub-cancel", nChannel);
-
- // Clear memory, no longer subscribed
- if (nChannel == MSG_PRODUCT)
- CRITICAL_BLOCK(cs_mapProducts)
- mapProducts.clear();
}
}
@@ -497,10 +492,6 @@ void CNode::Cleanup()
// All of a nodes broadcasts and subscriptions are automatically torn down
// when it goes down, so a node has to stay up to keep its broadcast going.
- CRITICAL_BLOCK(cs_mapProducts)
- for (map<uint256, CProduct>::iterator mi = mapProducts.begin(); mi != mapProducts.end();)
- AdvertRemoveSource(this, MSG_PRODUCT, 0, (*(mi++)).second);
-
// Cancel subscriptions
for (unsigned int nChannel = 0; nChannel < vfSubscribe.size(); nChannel++)
if (vfSubscribe[nChannel])
View
6 net.h
@@ -341,19 +341,13 @@ enum
{
MSG_TX = 1,
MSG_BLOCK,
- MSG_REVIEW,
- MSG_PRODUCT,
- MSG_TABLE,
};
static const char* ppszTypeName[] =
{
"ERROR",
"tx",
"block",
- "review",
- "product",
- "table",
};
class CInv
View
@@ -20,7 +20,7 @@ class CDataStream;
class CAutoFile;
static const int VERSION = 201;
-static const char* pszSubVer = ".1";
+static const char* pszSubVer = ".2";
View
930 ui.cpp

Large diffs are not rendered by default.

Oops, something went wrong.
View
142 ui.h
@@ -6,12 +6,6 @@
DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
-DECLARE_EVENT_TYPE(wxEVT_REPLY1, -1)
-DECLARE_EVENT_TYPE(wxEVT_REPLY2, -1)
-DECLARE_EVENT_TYPE(wxEVT_REPLY3, -1)
-
-
-
extern map<string, string> mapArgs;
@@ -57,8 +51,8 @@ class CMainFrame : public CMainFrameBase
void OnButtonAddressBook(wxCommandEvent& event);
void OnSetFocusAddress(wxFocusEvent& event);
void OnMouseEventsAddress(wxMouseEvent& event);
- void OnButtonCopy(wxCommandEvent& event);
void OnButtonChange(wxCommandEvent& event);
+ void OnButtonCopy(wxCommandEvent& event);
void OnListColBeginDrag(wxListEvent& event);
void OnListItemActivated(wxListEvent& event);
void OnListItemActivatedProductsSent(wxListEvent& event);
@@ -263,138 +257,6 @@ class CAddressBookDialog : public CAddressBookDialogBase
-class CProductsDialog : public CProductsDialogBase
-{
-protected:
- // Event handlers
- void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
- void OnCombobox(wxCommandEvent& event);
- void OnButtonSearch(wxCommandEvent& event);
- void OnListItemActivated(wxListEvent& event);
-
-public:
- /** Constructor */
- CProductsDialog(wxWindow* parent);
-
- // Custom
- vector<CProduct> m_vProduct;
-};
-
-
-
-class CEditProductDialog : public CEditProductDialogBase
-{
-protected:
- // Event handlers
- void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
- void OnButtonDel0(wxCommandEvent& event);
- void OnButtonDel1(wxCommandEvent& event);
- void OnButtonDel2(wxCommandEvent& event);
- void OnButtonDel3(wxCommandEvent& event);
- void OnButtonDel4(wxCommandEvent& event);
- void OnButtonDel5(wxCommandEvent& event);
- void OnButtonDel6(wxCommandEvent& event);
- void OnButtonDel7(wxCommandEvent& event);
- void OnButtonDel8(wxCommandEvent& event);
- void OnButtonDel9(wxCommandEvent& event);
- void OnButtonDel10(wxCommandEvent& event);
- void OnButtonDel11(wxCommandEvent& event);
- void OnButtonDel12(wxCommandEvent& event);
- void OnButtonDel13(wxCommandEvent& event);
- void OnButtonDel14(wxCommandEvent& event);
- void OnButtonDel15(wxCommandEvent& event);
- void OnButtonDel16(wxCommandEvent& event);
- void OnButtonDel17(wxCommandEvent& event);
- void OnButtonDel18(wxCommandEvent& event);
- void OnButtonDel19(wxCommandEvent& event);
- void OnButtonAddField(wxCommandEvent& event);
- void OnButtonSend(wxCommandEvent& event);
- void OnButtonPreview(wxCommandEvent& event);
- void OnButtonCancel(wxCommandEvent& event);
-
-public:
- /** Constructor */
- CEditProductDialog(wxWindow* parent);
-
- // Custom
- enum { FIELDS_MAX = 20 };
- wxTextCtrl* m_textCtrlLabel[FIELDS_MAX];
- wxTextCtrl* m_textCtrlField[FIELDS_MAX];
- wxButton* m_buttonDel[FIELDS_MAX];
-
- void LayoutAll();
- void ShowLine(int i, bool fShow=true);
- void OnButtonDel(wxCommandEvent& event, int n);
- void SetProduct(const CProduct& productIn);
- void GetProduct(CProduct& product);
-
-};
-
-
-
-class CViewProductDialog : public CViewProductDialogBase
-{
-protected:
- // Event handlers
- void OnButtonSubmitForm(wxCommandEvent& event);
- void OnButtonCancelForm(wxCommandEvent& event);
- void OnButtonBack(wxCommandEvent& event);
- void OnButtonNext(wxCommandEvent& event);
- void OnButtonCancel(wxCommandEvent& event);
-
-public:
- /** Constructor */
- CViewProductDialog(wxWindow* parent, const CProduct& productIn);
- ~CViewProductDialog();
-
- // Custom
- CProduct product;
- enum { FIELDS_MAX = 20 };
- wxStaticText* m_staticTextLabel[FIELDS_MAX];
- wxTextCtrl* m_textCtrlField[FIELDS_MAX];
- wxChoice* m_choiceField[FIELDS_MAX];
-
- void GetOrder(CWalletTx& order);
- void UpdateProductDisplay(bool fDetails);
- void OnReply1(wxCommandEvent& event);
-};
-
-
-
-class CViewOrderDialog : public CViewOrderDialogBase
-{
-protected:
- // Event handlers
- void OnButtonOK(wxCommandEvent& event);
-
-public:
- /** Constructor */
- CViewOrderDialog(wxWindow* parent, CWalletTx order, bool fReceived);
-
- // Custom
- bool fReceived;
-};
-
-
-
-class CEditReviewDialog : public CEditReviewDialogBase
-{
-protected:
- // Event handlers
- void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
- void OnButtonSubmit(wxCommandEvent& event);
- void OnButtonCancel(wxCommandEvent& event);
-
-public:
- /** Constructor */
- CEditReviewDialog(wxWindow* parent);
-
- // Custom
- void GetReview(CReview& review);
-};
-
-
-
class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
{
protected:
@@ -430,6 +292,8 @@ class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
m_textCtrl2->SetValue(strValue2);
SetSize(wxDefaultCoord, 180);
}
+ if (!fWindows)
+ SetSize(1.14 * GetSize().GetWidth(), 1.14 * GetSize().GetHeight());
}
// Custom
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
287 uibase.h

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.