-
Notifications
You must be signed in to change notification settings - Fork 118
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
[x/programs] refactor init #432
Conversation
@@ -8,6 +8,8 @@ import ( | |||
) | |||
|
|||
type Runtime interface { | |||
// Create initializes and calls the init function. | |||
Create(context.Context, []byte) (uint64, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this is actually a necessary part of the runtime interface. Once the runtime is initialized then the user can make whatever call they want. My understanding is that a programID would be the result of a transaction generated by the VM.
@@ -44,6 +44,27 @@ type runtime struct { | |||
log logging.Logger | |||
} | |||
|
|||
func (r *runtime) Create(ctx context.Context, programBytes []byte) (uint64, error) { | |||
err := r.Initialize(ctx, programBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why isn't this part of Initialize
Runtime?
programID := initProgramStorage() | ||
|
||
// call initialize | ||
result, err := r.Call(ctx, "init", uint64(programID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init in this context is perhaps required by the examples as they are now but as stated above the programID is going to be the result something like a create_program
action. I would like us moving towards that direction in each iteration if possible.
// Initialize the program with no fields | ||
Program::new().into() | ||
true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fact that we end up with a hard coded bool here speaks to the fact that init should not be a requirement.
Removes
initialize_program
host function and theProgram
struct in Rust.Instead we generate and initialize the programs storage and id in
go
and inject it into theinit
function.Changes
Program
folderinitialize_function
Create
method to the go runtime that sets up global storage and callsinit
on the programCreate
"publishes" the program, whileInitialize
grabs the published program.Context