@ -4,6 +4,18 @@ import (
"encoding/hex"
"errors"
"fmt"
ethereum_rpc "github.com/ethereum/go-ethereum/rpc"
"github.com/harmony-one/go-sdk/pkg/account"
"github.com/harmony-one/go-sdk/pkg/address"
"github.com/harmony-one/go-sdk/pkg/common"
"github.com/harmony-one/go-sdk/pkg/console/jsre"
"github.com/harmony-one/go-sdk/pkg/console/jsre/deps"
"github.com/harmony-one/go-sdk/pkg/console/prompt"
"github.com/harmony-one/go-sdk/pkg/console/web3ext"
"github.com/harmony-one/go-sdk/pkg/rpc"
"github.com/harmony-one/go-sdk/pkg/store"
"github.com/harmony-one/go-sdk/pkg/transaction"
"github.com/harmony-one/harmony/accounts"
"io"
"io/ioutil"
"math/big"
@ -17,19 +29,6 @@ import (
"syscall"
"time"
ethereum_rpc "github.com/ethereum/go-ethereum/rpc"
"github.com/woop-chain/go-sdk/pkg/account"
"github.com/woop-chain/go-sdk/pkg/address"
"github.com/woop-chain/go-sdk/pkg/common"
"github.com/woop-chain/go-sdk/pkg/console/jsre"
"github.com/woop-chain/go-sdk/pkg/console/jsre/deps"
"github.com/woop-chain/go-sdk/pkg/console/prompt"
"github.com/woop-chain/go-sdk/pkg/console/web3ext"
"github.com/woop-chain/go-sdk/pkg/rpc"
"github.com/woop-chain/go-sdk/pkg/store"
"github.com/woop-chain/go-sdk/pkg/transaction"
"github.com/woop-chain/woop/accounts"
"github.com/dop251/goja"
"github.com/mattn/go-colorable"
"github.com/peterh/liner"
@ -58,9 +57,9 @@ type Config struct {
Prompter prompt . UserPrompter // Input prompter to allow interactive user feedback (defaults to TerminalPrompter)
Printer io . Writer // Output writer to serialize any display strings to (defaults to os.Stdout)
Preload [ ] string // Absolute paths to JavaScript files to preload
NodeUrl string // Wiki Node url
ShardId int // Wiki Shard ID
Net string // Wiki Network
NodeUrl string // Hmy Node url
ShardId int // Hmy Shard ID
Net string // Hmy Network
}
// Console is a JavaScript interpreted runtime environment. It is a fully fledged
@ -74,9 +73,9 @@ type Console struct {
histPath string // Absolute path to the console scrollback history
history [ ] string // Scroll history maintained by the console
printer io . Writer // Output writer to serialize any display strings to
nodeUrl string // Wiki Node url
shardId int // Wiki Shard ID
net string // Wiki Network
nodeUrl string // Hmy Node url
shardId int // Hmy Shard ID
net string // Hmy Network
}
// New initializes a JavaScript interpreted runtime environment and sets defaults
@ -243,14 +242,14 @@ func (c *Console) initPersonal(vm *goja.Runtime, bridge *bridge) {
if personal == nil || c . prompter == nil {
return
}
personal . Set ( "getListAccounts" , jsre . MakeCallback ( vm , bridge . Wiki GetListAccounts) )
personal . Set ( "signTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki SignTransaction) ) )
personal . Set ( "sendTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki SendTransaction) ) )
personal . Set ( "lockAccount" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki LockAccount) ) )
personal . Set ( "importRawKey" , jsre . MakeCallback ( vm , bridge . Wiki ImportRawKey) )
personal . Set ( "unlockAccount" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki UnlockAccount) ) )
personal . Set ( "newAccount" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki NewAccount) ) )
personal . Set ( "sign" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki Sign) ) )
personal . Set ( "getListAccounts" , jsre . MakeCallback ( vm , bridge . Hmy GetListAccounts) )
personal . Set ( "signTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy SignTransaction) ) )
personal . Set ( "sendTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy SendTransaction) ) )
personal . Set ( "lockAccount" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy LockAccount) ) )
personal . Set ( "importRawKey" , jsre . MakeCallback ( vm , bridge . Hmy ImportRawKey) )
personal . Set ( "unlockAccount" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy UnlockAccount) ) )
personal . Set ( "newAccount" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy NewAccount) ) )
personal . Set ( "sign" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy Sign) ) )
_ , err := vm . RunString ( ` Object.defineProperty(personal, "listAccounts", { get: personal.getListAccounts}); ` )
if err != nil {
@ -264,8 +263,8 @@ func (c *Console) initEth(vm *goja.Runtime, bridge *bridge) {
return
}
eth . Set ( "sendTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki SendTransaction) ) )
eth . Set ( "signTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Wiki SignTransaction) ) )
eth . Set ( "sendTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy SendTransaction) ) )
eth . Set ( "signTransaction" , jsre . MakeCallback ( vm , bridge . callbackProtected ( bridge . Hmy SignTransaction) ) )
}
func ( c * Console ) clearHistory ( ) {
@ -319,7 +318,7 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
// Welcome show summary of current Geth instance and some metadata about the
// console's available modules.
func ( c * Console ) Welcome ( ) {
message := "Welcome to the Wiki JavaScript console!\n\n"
message := "Welcome to the Hmy JavaScript console!\n\n"
// Print some generic Geth metadata
if res , err := c . jsre . Run ( `
@ -327,7 +326,7 @@ func (c *Console) Welcome() {
try {
message += "coinbase: " + eth . coinbase + "\n" ;
} catch ( err ) { }
message += "at shard: " + wiki . shardID + "\n" ;
message += "at shard: " + hmy . shardID + "\n" ;
message += "at block: " + eth . blockNumber + " (" + new Date ( 1000 * eth . getBlock ( eth . blockNumber ) . timestamp ) + ")\n" ;
try {
message += " datadir: " + admin . datadir + "\n" ;
@ -531,7 +530,7 @@ func (b *bridge) callbackProtected(protectedFunc func(call jsre.Call) (goja.Valu
}
}
func ( b * bridge ) Wiki GetListAccounts( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy GetListAccounts( call jsre . Call ) ( goja . Value , error ) {
var accounts = [ ] string { }
for _ , name := range store . LocalAccounts ( ) {
@ -545,7 +544,7 @@ func (b *bridge) WikiGetListAccounts(call jsre.Call) (goja.Value, error) {
return call . VM . ToValue ( accounts ) , nil
}
func ( b * bridge ) Wiki SignTransaction( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy SignTransaction( call jsre . Call ) ( goja . Value , error ) {
txObj := call . Arguments [ 0 ] . ToObject ( call . VM )
password := call . Arguments [ 1 ] . String ( )
@ -554,10 +553,6 @@ func (b *bridge) WikiSignTransaction(call jsre.Call) (goja.Value, error) {
gasLimit := getStringFromJsObjWithDefault ( txObj , "gas" , "1000000" )
amount := getStringFromJsObjWithDefault ( txObj , "value" , "0" )
gasPrice := getStringFromJsObjWithDefault ( txObj , "gasPrice" , "1" )
input , err := transaction . StringToByte ( getStringFromJsObjWithDefault ( txObj , "data" , "" ) )
if err != nil {
return nil , err
}
networkHandler := rpc . NewHTTPHandler ( b . console . nodeUrl )
chanId , err := common . StringToChainID ( b . console . net )
@ -603,7 +598,7 @@ func (b *bridge) WikiSignTransaction(call jsre.Call) (goja.Value, error) {
toP ,
uint32 ( b . console . shardId ) , uint32 ( b . console . shardId ) ,
amt , gPrice ,
input ,
[ ] byte { } ,
)
if err != nil {
return nil , err
@ -628,7 +623,7 @@ func (b *bridge) WikiSignTransaction(call jsre.Call) (goja.Value, error) {
} ) , nil
}
func ( b * bridge ) Wiki SendTransaction( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy SendTransaction( call jsre . Call ) ( goja . Value , error ) {
txObj := call . Arguments [ 0 ] . ToObject ( call . VM )
password := ""
if len ( call . Arguments ) > 1 {
@ -640,10 +635,6 @@ func (b *bridge) WikiSendTransaction(call jsre.Call) (goja.Value, error) {
gasLimit := getStringFromJsObjWithDefault ( txObj , "gas" , "1000000" )
amount := getStringFromJsObjWithDefault ( txObj , "value" , "0" )
gasPrice := getStringFromJsObjWithDefault ( txObj , "gasPrice" , "1" )
input , err := transaction . StringToByte ( getStringFromJsObjWithDefault ( txObj , "data" , "" ) )
if err != nil {
return nil , err
}
networkHandler := rpc . NewHTTPHandler ( b . console . nodeUrl )
chanId , err := common . StringToChainID ( b . console . net )
@ -689,7 +680,7 @@ func (b *bridge) WikiSendTransaction(call jsre.Call) (goja.Value, error) {
toP ,
uint32 ( b . console . shardId ) , uint32 ( b . console . shardId ) ,
amt , gPrice ,
input ,
[ ] byte { } ,
)
if err != nil {
return nil , err
@ -698,7 +689,7 @@ func (b *bridge) WikiSendTransaction(call jsre.Call) (goja.Value, error) {
return call . VM . ToValue ( * ctrlr . TransactionHash ( ) ) , nil
}
func ( b * bridge ) Wiki LockAccount( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy LockAccount( call jsre . Call ) ( goja . Value , error ) {
address := call . Arguments [ 0 ] . String ( )
_ , _ , err := store . LockKeystore ( address )
@ -709,7 +700,7 @@ func (b *bridge) WikiLockAccount(call jsre.Call) (goja.Value, error) {
return goja . Null ( ) , nil
}
func ( b * bridge ) Wiki ImportRawKey( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy ImportRawKey( call jsre . Call ) ( goja . Value , error ) {
privateKey := call . Arguments [ 0 ] . String ( )
password := call . Arguments [ 1 ] . String ( )
@ -721,7 +712,7 @@ func (b *bridge) WikiImportRawKey(call jsre.Call) (goja.Value, error) {
return call . VM . ToValue ( name ) , nil
}
func ( b * bridge ) Wiki UnlockAccount( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy UnlockAccount( call jsre . Call ) ( goja . Value , error ) {
if len ( call . Arguments ) < 3 {
return nil , errors . New ( "arguments < 3" )
}
@ -737,11 +728,11 @@ func (b *bridge) WikiUnlockAccount(call jsre.Call) (goja.Value, error) {
return goja . Null ( ) , nil
}
func ( b * bridge ) Wiki NewAccount( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy NewAccount( call jsre . Call ) ( goja . Value , error ) {
return goja . Null ( ) , nil
}
func ( b * bridge ) Wiki Sign( call jsre . Call ) ( goja . Value , error ) {
func ( b * bridge ) Hmy Sign( call jsre . Call ) ( goja . Value , error ) {
dataToSign := call . Arguments [ 0 ] . String ( )
addressStr := call . Arguments [ 1 ] . String ( )
password := call . Arguments [ 2 ] . String ( )