aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth/admin.go
blob: 949a7bde085f3dc0e8f3eda9ac555de6831e4e28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
package main

import (
    "encoding/json"
    "errors"
    "fmt"
    "math/big"
    "strconv"
    "time"

    "github.com/ethereum/go-ethereum/cmd/utils"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/common/compiler"
    "github.com/ethereum/go-ethereum/common/natspec"
    "github.com/ethereum/go-ethereum/common/resolver"
    "github.com/ethereum/go-ethereum/core/state"
    "github.com/ethereum/go-ethereum/core/types"
    "github.com/ethereum/go-ethereum/core/vm"
    "github.com/ethereum/go-ethereum/crypto"
    "github.com/ethereum/go-ethereum/logger/glog"
    "github.com/ethereum/go-ethereum/rlp"
    "github.com/ethereum/go-ethereum/rpc"
    "github.com/ethereum/go-ethereum/xeth"
    "github.com/robertkrimen/otto"
    "gopkg.in/fatih/set.v0"
)

/*
node admin bindings
*/

func (js *jsre) adminBindings() {
    ethO, _ := js.re.Get("eth")
    eth := ethO.Object()
    eth.Set("pendingTransactions", js.pendingTransactions)
    eth.Set("resend", js.resend)

    js.re.Set("admin", struct{}{})
    t, _ := js.re.Get("admin")
    admin := t.Object()
    admin.Set("addPeer", js.addPeer)
    admin.Set("startRPC", js.startRPC)
    admin.Set("stopRPC", js.stopRPC)
    admin.Set("nodeInfo", js.nodeInfo)
    admin.Set("peers", js.peers)
    admin.Set("newAccount", js.newAccount)
    admin.Set("unlock", js.unlock)
    admin.Set("import", js.importChain)
    admin.Set("export", js.exportChain)
    admin.Set("verbosity", js.verbosity)
    admin.Set("progress", js.downloadProgress)
    admin.Set("setSolc", js.setSolc)

    admin.Set("contractInfo", struct{}{})
    t, _ = admin.Get("contractInfo")
    cinfo := t.Object()
    // newRegistry officially not documented temporary option
    cinfo.Set("start", js.startNatSpec)
    cinfo.Set("stop", js.stopNatSpec)
    cinfo.Set("newRegistry", js.newRegistry)
    cinfo.Set("get", js.getContractInfo)
    cinfo.Set("register", js.register)
    cinfo.Set("registerUrl", js.registerUrl)
    // cinfo.Set("verify", js.verify)

    admin.Set("miner", struct{}{})
    t, _ = admin.Get("miner")
    miner := t.Object()
    miner.Set("start", js.startMining)
    miner.Set("stop", js.stopMining)
    miner.Set("hashrate", js.hashrate)
    miner.Set("setExtra", js.setExtra)
    miner.Set("setGasPrice", js.setGasPrice)

    admin.Set("debug", struct{}{})
    t, _ = admin.Get("debug")
    debug := t.Object()
    js.re.Set("sleep", js.sleep)
    debug.Set("backtrace", js.backtrace)
    debug.Set("printBlock", js.printBlock)
    debug.Set("dumpBlock", js.dumpBlock)
    debug.Set("getBlockRlp", js.getBlockRlp)
    debug.Set("setHead", js.setHead)
    debug.Set("processBlock", js.debugBlock)
    // undocumented temporary
    debug.Set("waitForBlocks", js.waitForBlocks)
}

// generic helper to getBlock by Number/Height or Hex depending on autodetected input
// if argument is missing the current block is returned
// if block is not found or there is problem with decoding
// the appropriate value is returned and block is guaranteed to be nil
func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
    var block *types.Block
    if len(call.ArgumentList) > 0 {
        if call.Argument(0).IsNumber() {
            num, _ := call.Argument(0).ToInteger()
            block = js.ethereum.ChainManager().GetBlockByNumber(uint64(num))
        } else if call.Argument(0).IsString() {
            hash, _ := call.Argument(0).ToString()
            block = js.ethereum.ChainManager().GetBlock(common.HexToHash(hash))
        } else {
            return nil, errors.New("invalid argument for dump. Either hex string or number")
        }
    } else {
        block = js.ethereum.ChainManager().CurrentBlock()
    }

    if block == nil {
        return nil, errors.New("block not found")
    }
    return block, nil
}

func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
    txs := js.ethereum.TxPool().GetTransactions()

    // grab the accounts from the account manager. This will help with determening which
    // transactions should be returned.
    accounts, err := js.ethereum.AccountManager().Accounts()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    // Add the accouns to a new set
    accountSet := set.New()
    for _, account := range accounts {
        accountSet.Add(common.BytesToAddress(account.Address))
    }

    //ltxs := make([]*tx, len(txs))
    var ltxs []*tx
    for _, tx := range txs {
        // no need to check err
        if from, _ := tx.From(); accountSet.Has(from) {
            ltxs = append(ltxs, newTx(tx))
        }
    }

    return js.re.ToVal(ltxs)
}

func (js *jsre) resend(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) == 0 {
        fmt.Println("first argument must be a transaction")
        return otto.FalseValue()
    }

    v, err := call.Argument(0).Export()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    if tx, ok := v.(*tx); ok {
        gl, gp := tx.GasLimit, tx.GasPrice
        if len(call.ArgumentList) > 1 {
            gp = call.Argument(1).String()
        }
        if len(call.ArgumentList) > 2 {
            gl = call.Argument(2).String()
        }

        ret, err := js.xeth.Transact(tx.From, tx.To, tx.Nonce, tx.Value, gl, gp, tx.Data)
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
        js.ethereum.TxPool().RemoveTransactions(types.Transactions{tx.tx})

        return js.re.ToVal(ret)
    }

    fmt.Println("first argument must be a transaction")
    return otto.FalseValue()
}

func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
    block, err := js.getBlock(call)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    old := vm.Debug
    vm.Debug = true
    _, err = js.ethereum.BlockProcessor().RetryProcess(block)
    if err != nil {
        glog.Infoln(err)
    }
    vm.Debug = old

    return otto.UndefinedValue()
}

func (js *jsre) setHead(call otto.FunctionCall) otto.Value {
    block, err := js.getBlock(call)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    js.ethereum.ChainManager().SetHead(block)
    return otto.UndefinedValue()
}

func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
    current, max := js.ethereum.Downloader().Stats()

    return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
}

func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
    block, err := js.getBlock(call)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    encoded, _ := rlp.EncodeToBytes(block)
    return js.re.ToVal(fmt.Sprintf("%x", encoded))
}

func (js *jsre) setExtra(call otto.FunctionCall) otto.Value {
    extra, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    if len(extra) > 1024 {
        fmt.Println("error: cannot exceed 1024 bytes")
        return otto.UndefinedValue()
    }

    js.ethereum.Miner().SetExtra([]byte(extra))
    return otto.UndefinedValue()
}

func (js *jsre) setGasPrice(call otto.FunctionCall) otto.Value {
    gasPrice, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    js.ethereum.Miner().SetGasPrice(common.String2Big(gasPrice))
    return otto.UndefinedValue()
}

func (js *jsre) hashrate(otto.FunctionCall) otto.Value {
    return js.re.ToVal(js.ethereum.Miner().HashRate())
}

func (js *jsre) backtrace(call otto.FunctionCall) otto.Value {
    tracestr, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    glog.GetTraceLocation().Set(tracestr)

    return otto.UndefinedValue()
}

func (js *jsre) verbosity(call otto.FunctionCall) otto.Value {
    v, err := call.Argument(0).ToInteger()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    glog.SetV(int(v))
    return otto.UndefinedValue()
}

func (js *jsre) startMining(call otto.FunctionCall) otto.Value {
    var (
        threads int64
        err     error
    )

    if len(call.ArgumentList) > 0 {
        threads, err = call.Argument(0).ToInteger()
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
    } else {
        threads = 4
    }

    err = js.ethereum.StartMining(int(threads))
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    return otto.TrueValue()
}

func (js *jsre) stopMining(call otto.FunctionCall) otto.Value {
    js.ethereum.StopMining()
    return otto.TrueValue()
}

func (js *jsre) startRPC(call otto.FunctionCall) otto.Value {
    addr, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    port, err := call.Argument(1).ToInteger()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    corsDomain := js.corsDomain
    if len(call.ArgumentList) > 2 {
        corsDomain, err = call.Argument(2).ToString()
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
    }

    config := rpc.RpcConfig{
        ListenAddress: addr,
        ListenPort:    uint(port),
        CorsDomain:    corsDomain,
    }

    xeth := xeth.New(js.ethereum, nil)
    err = rpc.Start(xeth, config)
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    return otto.TrueValue()
}

func (js *jsre) stopRPC(call otto.FunctionCall) otto.Value {
    if rpc.Stop() == nil {
        return otto.TrueValue()
    }
    return otto.FalseValue()
}

func (js *jsre) addPeer(call otto.FunctionCall) otto.Value {
    nodeURL, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    err = js.ethereum.AddPeer(nodeURL)
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    return otto.TrueValue()
}

func (js *jsre) unlock(call otto.FunctionCall) otto.Value {
    addr, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    seconds, err := call.Argument(2).ToInteger()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    arg := call.Argument(1)
    var passphrase string
    if arg.IsUndefined() {
        fmt.Println("Please enter a passphrase now.")
        passphrase, err = readPassword("Passphrase: ", true)
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
    } else {
        passphrase, err = arg.ToString()
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
    }
    am := js.ethereum.AccountManager()
    err = am.TimedUnlock(common.HexToAddress(addr), passphrase, time.Duration(seconds)*time.Second)
    if err != nil {
        fmt.Printf("Unlock account failed '%v'\n", err)
        return otto.FalseValue()
    }
    return otto.TrueValue()
}

func (js *jsre) newAccount(call otto.FunctionCall) otto.Value {
    arg := call.Argument(0)
    var passphrase string
    if arg.IsUndefined() {
        fmt.Println("The new account will be encrypted with a passphrase.")
        fmt.Println("Please enter a passphrase now.")
        auth, err := readPassword("Passphrase: ", true)
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
        confirm, err := readPassword("Repeat Passphrase: ", false)
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
        if auth != confirm {
            fmt.Println("Passphrases did not match.")
            return otto.FalseValue()
        }
        passphrase = auth
    } else {
        var err error
        passphrase, err = arg.ToString()
        if err != nil {
            fmt.Println(err)
            return otto.FalseValue()
        }
    }
    acct, err := js.ethereum.AccountManager().NewAccount(passphrase)
    if err != nil {
        fmt.Printf("Could not create the account: %v", err)
        return otto.UndefinedValue()
    }
    return js.re.ToVal(acct.Address.Hex())
}

func (js *jsre) nodeInfo(call otto.FunctionCall) otto.Value {
    return js.re.ToVal(js.ethereum.NodeInfo())
}

func (js *jsre) peers(call otto.FunctionCall) otto.Value {
    return js.re.ToVal(js.ethereum.PeersInfo())
}

func (js *jsre) importChain(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) == 0 {
        fmt.Println("require file name. admin.importChain(filename)")
        return otto.FalseValue()
    }
    fn, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    if err := utils.ImportChain(js.ethereum.ChainManager(), fn); err != nil {
        fmt.Println("Import error: ", err)
        return otto.FalseValue()
    }
    return otto.TrueValue()
}

func (js *jsre) exportChain(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) == 0 {
        fmt.Println("require file name: admin.exportChain(filename)")
        return otto.FalseValue()
    }

    fn, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    if err := utils.ExportChain(js.ethereum.ChainManager(), fn); err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    return otto.TrueValue()
}

func (js *jsre) printBlock(call otto.FunctionCall) otto.Value {
    block, err := js.getBlock(call)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    fmt.Println(block)

    return otto.UndefinedValue()
}

func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value {
    block, err := js.getBlock(call)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    statedb := state.New(block.Root(), js.ethereum.StateDb())
    dump := statedb.RawDump()
    return js.re.ToVal(dump)
}

func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) > 2 {
        fmt.Println("requires 0, 1 or 2 arguments: admin.debug.waitForBlock(minHeight, timeout)")
        return otto.FalseValue()
    }
    var n, timeout int64
    var timer <-chan time.Time
    var height *big.Int
    var err error
    args := len(call.ArgumentList)
    if args == 2 {
        timeout, err = call.Argument(1).ToInteger()
        if err != nil {
            fmt.Println(err)
            return otto.UndefinedValue()
        }
        timer = time.NewTimer(time.Duration(timeout) * time.Second).C
    }
    if args >= 1 {
        n, err = call.Argument(0).ToInteger()
        if err != nil {
            fmt.Println(err)
            return otto.UndefinedValue()
        }
        height = big.NewInt(n)
    }

    if args == 0 {
        height = js.xeth.CurrentBlock().Number()
        height.Add(height, common.Big1)
    }

    wait := js.wait
    js.wait <- height
    select {
    case <-timer:
        // if times out make sure the xeth loop does not block
        go func() {
            select {
            case wait <- nil:
            case <-wait:
            }
        }()
        return otto.UndefinedValue()
    case height = <-wait:
    }
    return js.re.ToVal(height.Uint64())
}

func (js *jsre) sleep(call otto.FunctionCall) otto.Value {
    sec, err := call.Argument(0).ToInteger()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    time.Sleep(time.Duration(sec) * time.Second)
    return otto.UndefinedValue()
}

func (js *jsre) setSolc(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) != 1 {
        fmt.Println("needs 1 argument: admin.contractInfo.setSolc(solcPath)")
        return otto.FalseValue()
    }
    solcPath, err := call.Argument(0).ToString()
    if err != nil {
        return otto.FalseValue()
    }
    solc, err := js.xeth.SetSolc(solcPath)
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }
    fmt.Println(solc.Info())
    return otto.TrueValue()
}

func (js *jsre) register(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) != 4 {
        fmt.Println("requires 4 arguments: admin.contractInfo.register(fromaddress, contractaddress, contract, filename)")
        return otto.UndefinedValue()
    }
    sender, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    address, err := call.Argument(1).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    raw, err := call.Argument(2).Export()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    jsonraw, err := json.Marshal(raw)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    var contract compiler.Contract
    err = json.Unmarshal(jsonraw, &contract)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    filename, err := call.Argument(3).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    contenthash, err := compiler.ExtractInfo(&contract, filename)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    // sender and contract address are passed as hex strings
    codeb := js.xeth.CodeAtBytes(address)
    codehash := common.BytesToHash(crypto.Sha3(codeb))

    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    registry := resolver.New(js.xeth)

    _, err = registry.RegisterContentHash(common.HexToAddress(sender), codehash, contenthash)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }

    return js.re.ToVal(contenthash.Hex())

}

func (js *jsre) registerUrl(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) != 3 {
        fmt.Println("requires 3 arguments: admin.contractInfo.register(fromaddress, contenthash, filename)")
        return otto.FalseValue()
    }
    sender, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    contenthash, err := call.Argument(1).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    url, err := call.Argument(2).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    registry := resolver.New(js.xeth)

    _, err = registry.RegisterUrl(common.HexToAddress(sender), common.HexToHash(contenthash), url)
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    return otto.TrueValue()
}

func (js *jsre) getContractInfo(call otto.FunctionCall) otto.Value {
    if len(call.ArgumentList) != 1 {
        fmt.Println("requires 1 argument: admin.contractInfo.register(contractaddress)")
        return otto.FalseValue()
    }
    addr, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    infoDoc, err := natspec.FetchDocsForContract(addr, js.xeth, ds)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    var info compiler.ContractInfo
    err = json.Unmarshal(infoDoc, &info)
    if err != nil {
        fmt.Println(err)
        return otto.UndefinedValue()
    }
    return js.re.ToVal(info)
}

func (js *jsre) startNatSpec(call otto.FunctionCall) otto.Value {
    js.ethereum.NatSpec = true
    return otto.TrueValue()
}

func (js *jsre) stopNatSpec(call otto.FunctionCall) otto.Value {
    js.ethereum.NatSpec = false
    return otto.TrueValue()
}

func (js *jsre) newRegistry(call otto.FunctionCall) otto.Value {

    if len(call.ArgumentList) != 1 {
        fmt.Println("requires 1 argument: admin.contractInfo.newRegistry(adminaddress)")
        return otto.FalseValue()
    }
    addr, err := call.Argument(0).ToString()
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    registry := resolver.New(js.xeth)
    err = registry.CreateContracts(common.HexToAddress(addr))
    if err != nil {
        fmt.Println(err)
        return otto.FalseValue()
    }

    return otto.TrueValue()
}

// internal transaction type which will allow us to resend transactions  using `eth.resend`
type tx struct {
    tx *types.Transaction

    To       string
    From     string
    Nonce    string
    Value    string
    Data     string
    GasLimit string
    GasPrice string
}

func newTx(t *types.Transaction) *tx {
    from, _ := t.From()
    var to string
    if t := t.To(); t != nil {
        to = t.Hex()
    }

    return &tx{
        tx:       t,
        To:       to,
        From:     from.Hex(),
        Value:    t.Amount.String(),
        Nonce:    strconv.Itoa(int(t.Nonce())),
        Data:     "0x" + common.Bytes2Hex(t.Data()),
        GasLimit: t.GasLimit.String(),
        GasPrice: t.GasPrice().String(),
    }
}