Ehtereum은 interactive방식(console)과 non-interactive방식(script) 모드를 사용할 수 있는 Javascript runtime environment(JSRE)를 지원한다.
Ethereum의 javascript console은 Web3 javascript Dapp API와 admin API를 제시한다.
Interactive 방식 : JSRE REPL (Read, Evaluate, Print Loop) Console
실행가능한 geth인 ethereum CLI는 javascript console을 갖고 있다. 이것은 console이나 attach 명령어로 시작된다.
console 시작명령은 geth node를 시작하고 console을 오픈한다. attach 시작명령은 geth node를 시작하지 않고 대신 실행중인 geth의 console을 오픈한다.
geth attach는 다음의 3가지 방식으로 접근 가능하다.
$ geth attach ipc:/some/custom/path
$ geth attach http://191.168.1.1:8545
$ geth attach ws://191.168.1.1:8546
기본적으로 geth node는 보안상의 이유로 기본적으로 http나 websocket서비스를 시작하지 않는다.
--rpcapi나 --wsapi 매개변수로 시작하거나 admin.startRPC, admin.startWS로 시작할 수 있다.
로그 정보를 보기 위해서는
$geth --versocity 5 console 2>> /tmp/eth.log 로 console출력을 파일출력으로 해주거나
$geth --versocity 5 console 2>> /dev/null 로 console출력을 억제해 줄 수 있다 또는
$geth --versocity 0 console 2 로 로그내용을 억제하는 방법도 가능하다.
geth가 실행될때 관리자의 요건을 우선 실행해 주는 방법으로 --preload 옵션이 있다.
$geth --preload "/eth/scripts/util.js" console
미리 실행되었으면 하는 내용을 util.js에 넣어 놓을 수 있다.
Non-interactive 방식 : JSRE script node
이것또한 javascript interpreter에게 실행파일을 실행하게 하거나 명령행을 실행하게 할 수 있다. --exec 옵션을 사용한다.
$geth --exec "eth.blockNumnber" attach
$geth --exec 'loadScript("myscript.js")' attach
주의사항
go-ethereum의 JSRE는 Otto JS VM을 사용하는데 몇가지 제약점이 있다.
- "use strict" 구문은 파싱은 하지만 실행은 못한다.
- 정규식표현처리(re2/regexp)의 전체 구문분석이 ECMA5 표준에 완벽히 일치하지는 않는다.
다른 알려진 Otto의 제약을 조심해야한다. Ethereum JSRE는 setTimeout과 setInterval을 모두 수용한다. 게다가 console은 admin.sleep(seconds)와 "admin.sleepBlocks(number)"도 지원한다.
따라서 web3.js는 bignumber.js라이브러리를 기본적으로 로드한다.
go-ethereum/internal/jsre/jsre.go
package jsre | |
import ( | |
crand "crypto/rand" | |
"encoding/binary" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"math/rand" | |
"time" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/internal/jsre/deps" | |
"github.com/robertkrimen/otto" | |
) | |
var ( | |
BigNumber_JS = deps.MustAsset("bignumber.js") | |
Web3_JS = deps.MustAsset("web3.js") | |
) |
ethereum cli에 제공되는 cli command의 힌트를 얻을 수 있는 부분이다.
# Package jsre provides execution environment for JavaScript.
#go-ehtereum CLI는 ECMA5기반의 REPL환경을 제공하며 JSRE환경에 따른 지원을 한다.
'Ethereum' 카테고리의 다른 글
ethereum wiki (0) | 2018.04.23 |
---|---|
이더리움의 합의알고리즘의 코드변경이 리뷰를 눈앞에 두고 있다 (0) | 2018.04.23 |
Welcom, Blockchain developers! (1) | 2018.03.20 |
The Ethereum Development Process (0) | 2018.03.20 |
Account Types, Gas and Transactions (0) | 2018.03.16 |