Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first attempt at on-chain rholang storage #282

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions bootstrap/deploy-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash

deployFiles() {
WAITPID=""
while read -r t;do
./deploy "$t"
# shellcheck disable=SC2030
WAITPID="$WAITPID $!"
done |tee -a log/deployment.log 2>&1
# shellcheck disable=SC2031,SC2086
wait $WAITPID
echo "$ME: done status $?"
}

get_type_value() {
head -n1 | sed '
s/.*\[//
s/\(.*\)].*/\1/
s/[\t "]*//g
s/,/ /g
s/[\t ][\t ]*/ /g
'
}

get_type_from_type_value() {
sed '
s/:[^ ]*//g
s/[\t ][\t ]*/ /g
'
}

get_value_from_type_value() {
t=$(cat -)
for i in $t;do
blah=$(sed 's/^[^:][^:]*://' <<< "$i")
if [ -z "$blah" ];then
blah="\"\""
fi
echo -n "$blah "
done
}

get_var() {
head -n 2|tail -n 1|sed '
s/.*\[//
s/\(.*\)].*/\1/
s/[\t ]*//g
s/,/ /g
s/[\t ][\t ]*/ /g
'
}

make_field() {
v=$(echo "$2"|cut -d' ' -f "$1")
t=$(echo "$3"|cut -d' ' -f "$1")
l=$(echo "$4"|cut -d' ' -f "$1")
if [ "$l" = "\"\"" ];then unset l;fi
if [ -z "$t" ];then t="string";fi
echo "\"$v\": { \"type\": \"$t\", \"value\": \"$l\" }"
}

createAction() {
type_value=$(get_type_value < "$1")
var=$(get_var < "$1")

type=$(echo "$type_value"|get_type_from_type_value)
val=$(echo "$type_value"|get_value_from_type_value)

echo "type_value=$type_value" >&2
echo "var=$var" >&2
echo "type=$type" >&2
echo "val=$val" >&2

unset fields
if [ -n "$var" ];then
len=$(echo "$var"|tr ' ' '\n'|wc -l)
len=$((len+1))
if [ $len -gt 1 ];then
fields=$(make_field 1 "$var" "$type" "$val")
for (( i=2; i<len; i++ ))
do
echo $fields
fields="$fields, $(make_field "$i" "$var" "$type" "$val")"
done
echo $fields
fi
fi
rholang=$(cat "$1"|sed 's,//.*,,'|sed 's/"/\\"/g')
# rholang=$(cat "$1")
str="
new __stdout(\`rho:io:stdout\`),__ret, __actDir, __deployerId(\`rho:rchain:deployerId\`) in {
for (@{\"write\": __w, ..._} <<- @[*__deployerId, \"ActionDictionary\"]) {
__stdout!({\"ActionDictionary write\": __w}) |
@__w!(\"$(basename "$1")\", { \"fields\": { $fields },
\"rholang\": \"$rholang\"}, *__ret)
}
|
new
mapCh
in {
for (r <- __ret) {
__stdout!({\"directory write\": *r}) |
for(@{\"read\": *read, ..._} <<- @[*__deployerId, \"ActionDictionary\"])
{ __stdout!([\"read\", *read])
| read!(*mapCh)
| for (map <- mapCh)
{ __stdout!(*map.keys().toList())
| __stdout!(*map)
}
}
}
}
}

"
echo "$str" >/tmp/actions/"$(basename "$1")"
}

rm -rf /tmp/actions
mkdir /tmp/actions

for i in ../src/actions/*.rho;do
createAction "$i"
done

ls /tmp/actions/*.rho|deployFiles
11 changes: 11 additions & 0 deletions bootstrap/listMasterURI.rho
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ in {
{ stdout!(["read", *read])
| deployerId!(["read", *read])
| read!(*mapCh)
| for (map <- mapCh)
{ stdout!(*map.keys().toList())
| deployerId!(["read", *read])
| stdout!(*map)
| deployerId!(*map)
}
} |
for(@{"read": *read, ..._} <<- @[*deployerId, "ActionDictionary"])
{ stdout!(["read", *read])
| deployerId!(["read", *read])
| read!(*mapCh)
| for (map <- mapCh)
{ stdout!(*map.keys().toList())
| deployerId!(["read", *read])
Expand Down
9 changes: 7 additions & 2 deletions bootstrap/master-contract-directory
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ new
,lookCh
,insertCh
,caps
,a_caps
,lastUri
EOF

Expand All @@ -37,9 +38,13 @@ in {
| for (Dir <- lookCh) {
Dir!(*caps)
| for (@{"read": read, "write": write, "grant": grant} <- caps) {

Dir!(*a_caps) |
for (@{"read": a_read, "write": a_write, "grant": a_grant} <- a_caps) {
@write!("ActionDictionary", a_read, *stdout)
| @[*deployerId, "ActionDictionary"]!({"read": a_read, "write": a_write, "grant": a_grant})
}
// Create a global reference to the master contract directory
@[*deployerId, "MasterContractAdmin"]!({"read": read, "write": write, "grant": grant})
| @[*deployerId, "MasterContractAdmin"]!({"read": read, "write": write, "grant": grant})
| insertArbitrary!(read, *insertCh)
| for (URI <- insertCh) {
stdout!({ "ReadcapURI": *URI})
Expand Down
6 changes: 3 additions & 3 deletions src/actions/addGroupToIssue.rho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
match ["inbox", "", ""] {
match ["string:inbox", "", ""] {
[lockerTag, group, issue] => {
new
stdout(`rho:io:stdout`),
Expand All @@ -8,7 +8,7 @@ match ["inbox", "", ""] {
in {
for(@{"peek": *peek, "URI": uri ..._} <<- @[*deployerId, lockerTag]) {
deployId!({"URI": uri}) |
new lockerCh, ret, ret1, ret2, ret3, loop in {
new lockerCh, ret, ret1, ret2, ret3, loop in {
peek!("Group", group, *ret) |
peek!("issue", issue, *ret1) |
for ( @[{"read": *read, ..._}, ..._] <- ret; @[{"admin": *admin, ..._}, ..._] <- ret1 ) {
Expand Down Expand Up @@ -38,5 +38,5 @@ match ["inbox", "", ""] {
}
}
}

}} // end of match
2 changes: 1 addition & 1 deletion src/actions/addMember.rho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
match ["?", "?", "?", "?", "inbox"] {
match ["", "", "", "", "string:inbox"] {
[name, revAddress, themBoxReg, group, lockerTag] => {
new
deployId(`rho:rchain:deployId`),
Expand Down
2 changes: 1 addition & 1 deletion src/actions/addVoterToIssue.rho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
match ["$inbox", `$voterURI`, "$issue"] {
match ["string:inbox", "uri:`voterURI`", "string:issue"] {
[lockerTag, toInboxURI, issue] => {
new
return(`rho:rchain:deployId`),
Expand Down
6 changes: 3 additions & 3 deletions src/actions/checkBalance.rho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
match ["$addr"] {
match ["walletRevAddr"] {
[myGovRevAddr] => {
new // use Explore to see result at return
return,
Expand All @@ -15,13 +15,13 @@ match ["$addr"] {
for (@balance <- balanceCh) {
return!(["#define", "$myBalance", balance])|
return!("${rev}.${fraction}" %% {
"rev": balance/100000000,
"rev": balance/100000000,
"fraction": ("${num}"%%{
"num": balance%100000000+100000000}).slice(1,9)
}
)
}
}
}
}
}
}} // end of match
8 changes: 4 additions & 4 deletions src/actions/createURI.rho
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
match ["value"] {
match ["string:value"] {
[value] => {
new
return(`rho:rchain:deployId`),
insert(`rho:registry:insertArbitrary`),
insert(`rho:registry:insertArbitrary`),
stdout(`rho:io:stdout`),
uriCh
in {
insert!(

value // enter value above or replace value here with longer rholang

, *uriCh) |
for (@URI <- uriCh) {
stdout!([ "URI", URI, "Obj", value]) |
Expand Down
2 changes: 1 addition & 1 deletion src/actions/newinbox.rho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
match [`$masterURI`] {
match [`MasterURI:$masterURI`] {
[ReadcapURI] => {
new
stdout(`rho:io:stdout`),
Expand Down
Loading