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

is the user creating a contract recorded in the state of the contract? #8

Open
vd1 opened this issue Mar 27, 2020 · 8 comments
Open

Comments

@vd1
Copy link

vd1 commented Mar 27, 2020

Or is that a piece of data that one has to add by hand in C.construct?

@adhusson
Copy link
Collaborator

You add it by hand.

@adhusson
Copy link
Collaborator

adhusson commented Mar 27, 2020

(it's the caller in construct, no need to add it as an argument)

@vd1
Copy link
Author

vd1 commented Mar 27, 2020

So I add a field let originator = data ~init:"" "originator" in the contract , and I put something like data_set originator get_caller in construct?

It doesn't really typecheck:

15 |     data_set originator get_caller
                             ^^^^^^^^^^
Error: This expression has type Address.t st
       but an expression was expected of type string

Can I store directly the address of the caller in originator instead of a string?

@adhusson
Copy link
Collaborator

adhusson commented Mar 27, 2020

That's the idea! You start with

let originator = data ~pp:Address.t "originator"

(no need for an initial value here, you will provide it in the constructor; anyway the initial value would have to be a dummy address to typecheck)

Then you can do

get_caller >>= fun caller -> data_set originator caller

or alternatively

let* caller = get_caller in data_set originator caller

the issue with data_set originator get_caller is that get_caller:Address.t st, while data_set: 'a key -> 'a -> unit st. That is: get_caller will return an address when given an environment, while data_set wants an address; doing

get_caller >>= fun caller -> data_set originator caller

composes 1) the application of get_caller to an environment and 2) the use of get_caller's return value by data_set.

@vd1
Copy link
Author

vd1 commented Mar 27, 2020

Yes OK! top it works except that I just do
let originator = data "originator"
because else I get

File "bin/example2_vd.ml", line 8, characters 28-37:
8 |   let originator = data ~pp:Address.t "originator"
                                ^^^^^^^^^
Error: Unbound value Address.t
a```

@vd1
Copy link
Author

vd1 commented Mar 27, 2020

the fun thing is that I can change the originator - so the access policies change over time:
tx userA c1A C1.set_originator userB
here userA cedes control of the phrase to userB as I modify the auth_code to this:

let auth_code1 = fun () ->
      let* caller = get_caller in
      let* orig = data_get C1.originator in
      if (caller = orig)
      then return ()
      else error "Not allowed to do this!" 

with this in place one needs to add little to be able to sell irreversibly the "admin rights" of a given contract! Of course you also have to be careful that only the current owner can change the owner field.

@adhusson
Copy link
Collaborator

My bad I meant Address.pp!

@vd1
Copy link
Author

vd1 commented Mar 27, 2020

got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants