-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from pipermerriam/piper/library-usage
Conversion of Grove into a library.
- Loading branch information
Showing
11 changed files
with
448 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Library Usage | ||
============= | ||
|
||
Grove can be used as a `solidity library <https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#libraries>`_, allowing use of all of Groves functionality using your own contracts storage. | ||
|
||
The primary Grove contract itself is actually just a wrapper around the | ||
deployed library contract. | ||
|
||
|
||
Example | ||
------- | ||
|
||
In this example, we will use a fictional contract ``Members`` which tracks | ||
information about some set of members for an organization. | ||
|
||
|
||
.. code-block:: solidity | ||
library GroveAPI { | ||
struct Index { | ||
bytes32 id; | ||
bytes32 name; | ||
bytes32 root; | ||
mapping (bytes32 => Node) nodes; | ||
} | ||
struct Node { | ||
bytes32 nodeId; | ||
bytes32 indexId; | ||
bytes32 id; | ||
int value; | ||
bytes32 parent; | ||
bytes32 left; | ||
bytes32 right; | ||
uint height; | ||
} | ||
function insert(Index storage index, bytes32 id, int value) public; | ||
function query(Index storage index, bytes2 operator, int value) public returns (bytes32); | ||
} | ||
contract Members { | ||
Grove.Index ageIndex; | ||
function addMember(bytes32 name, uint age) { | ||
... // Do whatever needs to be done to add the member. | ||
// Update the ageIndex with this new member's age. | ||
Grove.insert(ageIndex, name, age); | ||
} | ||
function isAnyoneThisOld(uint age) constant returns (bool) { | ||
return Grove.query("==", age) != 0x0; | ||
} | ||
} | ||
The ``Members`` contract above interfaces with the Grove library in two places. | ||
|
||
First, within the ``addMember`` function, everytime a member is added to the | ||
organization, their age is tracked in the ``ageIndex``. | ||
|
||
Second, the ``isAnyoneThisOld`` allows checking whether any member is a | ||
specific age. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters