$ make build
$ make start
Open http://localhost in your browser.
The overall design of the system:
api servers browser
-> geth -> metamask
| |
| |
\ /
controller contract
|
|
storage contract
Used for underlying storage - this is the stateful contract and should never need updating.
It has a simple map[string]string
structure and does not understand the
structure of keys
values
-map[string]string
controllerAddress
-address
function write(key, value) {
if(sender.address != controllerAddress) return
values[key] = value
}
function updateControllerAddress(address) {
if(sender.address != contract.owner) return
controllerAddress = address
}
The underlying key structure for receipts:
owner + previousHash + contentHash
storageContractAddress
-address
function findReceipts(field, value) {
let results = []
for (key, content in storage.values) {
const {owner, previousHash, contentHash} = receipt = key.split()
receipt.content = receipt
if(key == 'owner' && owner == value) results.push(receipt)
if(key == 'previousHash' && previousHash == value) results.push(receipt)
if(key == 'contentHash' && contentHash == value) results.push(receipt)
}
return results
}
function findReceipt(field, value) {
results = findReceipts(field, value)
return results[0]
}
function loadReceiptChain(id) {
let currentChain = findReceipt('contentHash', id)
let results = [currentChain]
while(currentChain.previousHash) {
currentChain = findReceipt('contentHash', currentChain.previousHash)
results.unshift(currentChain)
}
return results
}
function loadAllChains(owner) {
const allReceipts = findReceipts('owner', owner)
let receipts = {}
let chains = {}
// TODO: work out how to return an array of chains where
// each item is the last thing in the chain
}
function getOwner() {
return sender.data.apiKey || sender.address
}
function create(content, previousHash) {
const owner = getOwner()
const contentHash = sha256(content)
if(previousHash) {
const previousReceipt = findReceipt('previousHash', previousHash)
if(previousReceipt.owner != owner) return
}
else {
previousHash sha256('')
}
storage.write([owner, previousHash, contentHash].join(':'), content)
}
function updateControllerAddress(address) {
if(sender.address != contract.owner) return
controllerAddress = address
}
If you are wanting to edit templtestack whilst hot reloading - then:
$ make linked
$ make frontend.cli
$ yarn run watch