diff --git a/_gen.go b/_gen.go new file mode 100644 index 0000000000..a98feaf4e7 --- /dev/null +++ b/_gen.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/tendermint/go-wire/gen" + _ "github.com/clipperhouse/stringer" +) diff --git a/tx.go b/tx.go new file mode 100644 index 0000000000..3ee3dc5fec --- /dev/null +++ b/tx.go @@ -0,0 +1,6 @@ +package basecoin + +// TODO: add some common functionality here... +// +gen wrapper:"Tx" +type TxInner interface { +} diff --git a/txinner_wrapper.go b/txinner_wrapper.go new file mode 100644 index 0000000000..cfc91b5b20 --- /dev/null +++ b/txinner_wrapper.go @@ -0,0 +1,46 @@ +// Generated by: main +// TypeWriter: wrapper +// Directive: +gen on TxInner + +package basecoin + +import ( + "github.com/tendermint/go-wire/data" +) + +// Auto-generated adapters for happily unmarshaling interfaces +// Apache License 2.0 +// Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com) + +type Tx struct { + TxInner "json:\"unwrap\"" +} + +var TxMapper = data.NewMapper(Tx{}) + +func (h Tx) MarshalJSON() ([]byte, error) { + return TxMapper.ToJSON(h.TxInner) +} + +func (h *Tx) UnmarshalJSON(data []byte) (err error) { + parsed, err := TxMapper.FromJSON(data) + if err == nil && parsed != nil { + h.TxInner = parsed.(TxInner) + } + return err +} + +// Unwrap recovers the concrete interface safely (regardless of levels of embeds) +func (h Tx) Unwrap() TxInner { + hi := h.TxInner + for wrap, ok := hi.(Tx); ok; wrap, ok = hi.(Tx) { + hi = wrap.TxInner + } + return hi +} + +func (h Tx) Empty() bool { + return h.TxInner == nil +} + +/*** below are bindings for each implementation ***/