neoneo-go/pkg/wire/payload/transaction/util.go
decentralisedkev f8979fe7af
Fix lint errors (#182)
* golint and minor changes to make code readable
2019-03-17 18:26:35 +00:00

62 lines
1.3 KiB
Go

package transaction
import (
"bufio"
"encoding/hex"
"errors"
"github.com/CityOfZion/neo-go/pkg/wire/payload/transaction/types"
)
// FromReader returns a transaction from a bufio.Reader
func FromReader(reader *bufio.Reader) (Transactioner, error) {
t, err := reader.Peek(1)
typ := types.TX(t[0])
var trans Transactioner
switch typ {
case types.Miner:
miner := NewMiner(0)
err = miner.Decode(reader)
trans = miner
case types.Contract:
contract := NewContract(0)
err = contract.Decode(reader)
trans = contract
case types.Invocation:
invoc := NewInvocation(0)
err = invoc.Decode(reader)
trans = invoc
case types.Claim:
claim := NewClaim(0)
err = claim.Decode(reader)
trans = claim
case types.Register:
reg := NewRegister(0)
err = reg.Decode(reader)
trans = reg
case types.Issue:
iss := NewIssue(0)
err = iss.Decode(reader)
trans = iss
case types.Publish:
pub := NewPublish(0)
err = pub.Decode(reader)
trans = pub
case types.State:
state := NewStateTX(0)
err = state.Decode(reader)
trans = state
case types.Enrollment:
enr := NewEnrollment(0)
err = enr.Decode(reader)
trans = enr
case types.Agency:
err = errors.New("unsupported transaction type: Agency")
default:
err = errors.New("unsupported transaction with byte type " + hex.EncodeToString([]byte{t[0]}))
}
return trans, err
}