2017-05-17 12:20:08 -07:00
|
|
|
package txs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tendermint/basecoin"
|
2017-05-17 12:30:13 -07:00
|
|
|
"github.com/tendermint/basecoin/types"
|
2017-05-17 12:20:08 -07:00
|
|
|
"github.com/tendermint/go-wire/data"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// for utils...
|
|
|
|
ByteRaw = 0x1
|
|
|
|
ByteFees = 0x2
|
|
|
|
ByteMulti = 0x3
|
|
|
|
|
|
|
|
// for signatures
|
|
|
|
ByteSig = 0x16
|
|
|
|
ByteMultiSig = 0x17
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// for utils...
|
|
|
|
TypeRaw = "raw"
|
|
|
|
TypeFees = "fee"
|
|
|
|
TypeMulti = "multi"
|
|
|
|
|
|
|
|
// for signatures
|
|
|
|
TypeSig = "sig"
|
|
|
|
TypeMultiSig = "multisig"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-05-17 12:30:13 -07:00
|
|
|
basecoin.TxMapper.
|
2017-05-18 08:11:26 -07:00
|
|
|
RegisterImplementation(Raw{}, TypeRaw, ByteRaw).
|
2017-05-17 12:30:13 -07:00
|
|
|
RegisterImplementation(&Fee{}, TypeFees, ByteFees)
|
2017-05-17 12:20:08 -07:00
|
|
|
}
|
|
|
|
|
2017-05-18 08:11:26 -07:00
|
|
|
// Raw just contains bytes that can be hex-ified
|
|
|
|
type Raw struct {
|
|
|
|
data.Bytes
|
2017-05-17 12:20:08 -07:00
|
|
|
}
|
2017-05-17 12:30:13 -07:00
|
|
|
|
2017-05-18 08:11:26 -07:00
|
|
|
func (r Raw) Wrap() basecoin.Tx {
|
|
|
|
return basecoin.Tx{r}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRaw(d []byte) Raw {
|
|
|
|
return Raw{data.Bytes(d)}
|
|
|
|
}
|
2017-05-17 12:30:13 -07:00
|
|
|
|
2017-05-18 08:11:26 -07:00
|
|
|
/**** Fee ****/
|
|
|
|
|
|
|
|
// Fee attaches a fee payment to the embedded tx
|
2017-05-17 12:30:13 -07:00
|
|
|
type Fee struct {
|
2017-05-18 08:11:26 -07:00
|
|
|
Tx basecoin.Tx `json:"tx"`
|
|
|
|
Fee types.Coin `json:"fee"`
|
|
|
|
Payer data.Bytes `json:"payer"` // the address who pays the fee
|
2017-05-17 12:30:13 -07:00
|
|
|
// Gas types.Coin `json:"gas"` // ?????
|
|
|
|
}
|
|
|
|
|
2017-05-18 08:11:26 -07:00
|
|
|
func NewFee(tx basecoin.Tx, fee types.Coin, addr []byte) *Fee {
|
|
|
|
return &Fee{Tx: tx, Fee: fee, Payer: addr}
|
2017-05-17 12:30:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fee) Wrap() basecoin.Tx {
|
|
|
|
return basecoin.Tx{f}
|
|
|
|
}
|
2017-05-18 08:11:26 -07:00
|
|
|
|
|
|
|
/**** MultiTx ******/
|
|
|
|
type MultiTx struct {
|
|
|
|
Txs []basecoin.Tx `json:"txs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMultiTx(txs ...basecoin.Tx) *MultiTx {
|
|
|
|
return &MultiTx{Txs: txs}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *MultiTx) Wrap() basecoin.Tx {
|
|
|
|
return basecoin.Tx{mt}
|
|
|
|
}
|