diff options
author | Wei-Ning Huang <w@cobinhood.com> | 2018-10-18 13:12:16 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:23:39 +0800 |
commit | db1d03b5c2a6fbe370526dfaf283638773bab032 (patch) | |
tree | 305237d4831233521fe46f5901c34c8baccf9d4d /core/types | |
parent | 12eb896a11eaf15712339ffa7eedf2b7c88fdfdd (diff) | |
download | go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.tar go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.tar.gz go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.tar.bz2 go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.tar.lz go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.tar.xz go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.tar.zst go-tangerine-db1d03b5c2a6fbe370526dfaf283638773bab032.zip |
core: vm: implement RAND opcode support
DEXON has a built-in on chain random oracle that allow one to retrieve a
random variable. Add a new opcode `RAND` to load the random variable
onto the stack.
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 1 | ||||
-rw-r--r-- | core/types/gen_header_json.go | 7 | ||||
-rw-r--r-- | core/types/gen_log_json.go | 2 | ||||
-rw-r--r-- | core/types/gen_tx_json.go | 2 |
4 files changed, 12 insertions, 0 deletions
diff --git a/core/types/block.go b/core/types/block.go index b568c2b37..ef2cb2c56 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -83,6 +83,7 @@ type Header struct { Extra []byte `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash"` Nonce BlockNonce `json:"nonce"` + Randomness []byte `json:"randomness" gencodec:"required"` } // field type overrides for gencodec diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 4c028337f..d06b07769 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -31,6 +31,7 @@ func (h Header) MarshalJSON() ([]byte, error) { Extra hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash"` Nonce BlockNonce `json:"nonce"` + Randomness []byte `json:"randomness" gencodec:"required"` Hash common.Hash `json:"hash"` } var enc Header @@ -49,6 +50,7 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.Extra = h.Extra enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce + enc.Randomness = h.Randomness enc.Hash = h.Hash() return json.Marshal(&enc) } @@ -71,6 +73,7 @@ func (h *Header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest *common.Hash `json:"mixHash"` Nonce *BlockNonce `json:"nonce"` + Randomness []byte `json:"randomness" gencodec:"required"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -134,5 +137,9 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.Nonce != nil { h.Nonce = *dec.Nonce } + if dec.Randomness == nil { + return errors.New("missing required field 'randomness' for Header") + } + h.Randomness = dec.Randomness return nil } diff --git a/core/types/gen_log_json.go b/core/types/gen_log_json.go index 4d24b92fd..e301a69c8 100644 --- a/core/types/gen_log_json.go +++ b/core/types/gen_log_json.go @@ -12,6 +12,7 @@ import ( var _ = (*logMarshaling)(nil) +// MarshalJSON marshals as JSON. func (l Log) MarshalJSON() ([]byte, error) { type Log struct { Address common.Address `json:"address" gencodec:"required"` @@ -37,6 +38,7 @@ func (l Log) MarshalJSON() ([]byte, error) { return json.Marshal(&enc) } +// UnmarshalJSON unmarshals from JSON. func (l *Log) UnmarshalJSON(input []byte) error { type Log struct { Address *common.Address `json:"address" gencodec:"required"` diff --git a/core/types/gen_tx_json.go b/core/types/gen_tx_json.go index b1415094b..2f216dfb9 100644 --- a/core/types/gen_tx_json.go +++ b/core/types/gen_tx_json.go @@ -13,6 +13,7 @@ import ( var _ = (*txdataMarshaling)(nil) +// MarshalJSON marshals as JSON. func (t txdata) MarshalJSON() ([]byte, error) { type txdata struct { AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"` @@ -40,6 +41,7 @@ func (t txdata) MarshalJSON() ([]byte, error) { return json.Marshal(&enc) } +// UnmarshalJSON unmarshals from JSON. func (t *txdata) UnmarshalJSON(input []byte) error { type txdata struct { AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` |