Compiles a raw oracle.
(oracle *pb.Oracle)
| 46 | |
| 47 | // Compiles a raw oracle. |
| 48 | func compile(oracle *pb.Oracle) (*compiled, error) { |
| 49 | callString, args, err := validate(oracle) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | // create the vm and define the oracle function |
| 54 | vm := otto.New() |
| 55 | if _, err := vm.Run(oracle.Code); err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | // use the vm to precompile the function call |
| 59 | call, _ := vm.Compile("", callString) |
| 60 | // done ^_^ |
| 61 | return &compiled{ |
| 62 | oracle: oracle, |
| 63 | pool: CreateExecutionPool(vm), |
| 64 | args: args, |
| 65 | argc: len(args), |
| 66 | call: call, |
| 67 | }, nil |
| 68 | } |