github.com/igggame/nebulas-go@v2.1.0+incompatible/cmd/v8/main.go (about)

     1  // Copyright (C) 2017 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  
    19  package main
    20  
    21  import (
    22  	"io/ioutil"
    23  	"log"
    24  	"os"
    25  	"time"
    26  
    27  	"github.com/nebulasio/go-nebulas/core"
    28  	"github.com/nebulasio/go-nebulas/core/state"
    29  	"github.com/nebulasio/go-nebulas/nf/nvm"
    30  	"github.com/nebulasio/go-nebulas/storage"
    31  )
    32  
    33  func main() {
    34  	data, _ := ioutil.ReadFile(os.Args[1])
    35  
    36  	mem, _ := storage.NewMemoryStorage()
    37  	context, _ := state.NewWorldState(nil, mem)
    38  	contract, _ := context.CreateContractAccount([]byte("account2"), nil, nil)
    39  
    40  	ctx, err := nvm.NewContext(core.MockBlock(nil, 1), nil, contract, context)
    41  	if err == nil {
    42  		engine := nvm.NewV8Engine(ctx)
    43  		result, err := engine.RunScriptSource(string(data), 0)
    44  
    45  		log.Fatalf("Result is %s. Err is %s", result, err)
    46  
    47  		time.Sleep(10 * time.Second)
    48  		engine.Dispose()
    49  	} else {
    50  		os.Exit(1)
    51  	}
    52  }