diff --git a/lib/block/operation.go b/lib/block/operation.go index 6275fed14..639a412ea 100644 --- a/lib/block/operation.go +++ b/lib/block/operation.go @@ -1,6 +1,7 @@ package block import ( + "encoding/json" "fmt" "boscoin.io/sebak/lib/common" @@ -42,7 +43,7 @@ func NewBlockOperationKey(opHash, txHash string) string { } func NewBlockOperationFromOperation(op operation.Operation, tx transaction.Transaction, blockHeight uint64, opIndex int) (BlockOperation, error) { - body, err := op.B.Serialize() + body, err := json.Marshal(op.B) if err != nil { return BlockOperation{}, err } diff --git a/lib/block/operation_test.go b/lib/block/operation_test.go index c522e9b2c..fa06ff67d 100644 --- a/lib/block/operation_test.go +++ b/lib/block/operation_test.go @@ -22,8 +22,7 @@ func TestNewBlockOperationFromOperation(t *testing.T) { require.Equal(t, bo.Type, op.H.Type) require.Equal(t, bo.TxHash, tx.H.Hash) require.Equal(t, bo.Source, tx.B.Source) - encoded, err := op.B.Serialize() - require.NoError(t, err) + encoded := common.MustMarshalJSON(op.B) require.Equal(t, bo.Body, encoded) } @@ -125,8 +124,7 @@ func TestBlockOperationSaveByTransaction(t *testing.T) { require.Equal(t, bo.Type, op.H.Type) require.Equal(t, bo.TxHash, tx.H.Hash) require.Equal(t, bo.Source, tx.B.Source) - encoded, err := op.B.Serialize() - require.NoError(t, err) + encoded := common.MustMarshalJSON(op.B) require.Equal(t, bo.Body, encoded) } } diff --git a/lib/transaction/operation/collect_tx_fee.go b/lib/transaction/operation/collect_tx_fee.go index 77ae236df..bf3b30638 100644 --- a/lib/transaction/operation/collect_tx_fee.go +++ b/lib/transaction/operation/collect_tx_fee.go @@ -1,8 +1,6 @@ package operation import ( - "encoding/json" - "boscoin.io/sebak/lib/common" "boscoin.io/sebak/lib/common/keypair" "boscoin.io/sebak/lib/errors" @@ -72,10 +70,6 @@ func (o CollectTxFee) GetAmount() common.Amount { return o.Amount } -func (o CollectTxFee) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} - func (o CollectTxFee) HasFee() bool { return false } diff --git a/lib/transaction/operation/congress_voting.go b/lib/transaction/operation/congress_voting.go index bda154d71..210d3ffb8 100644 --- a/lib/transaction/operation/congress_voting.go +++ b/lib/transaction/operation/congress_voting.go @@ -1,8 +1,6 @@ package operation import ( - "encoding/json" - "boscoin.io/sebak/lib/common" "boscoin.io/sebak/lib/errors" ) @@ -33,10 +31,6 @@ func NewCongressVoting(contract string, start, end uint64, amount common.Amount, } } -func (o CongressVoting) Serialize() (encoded []byte, err error) { - encoded, err = json.Marshal(o) - return -} func (o CongressVoting) IsWellFormed(common.Config) (err error) { if len(o.Contract) == 0 { return errors.OperationBodyInsufficient diff --git a/lib/transaction/operation/congress_voting_result.go b/lib/transaction/operation/congress_voting_result.go index c76a3cb09..0d489b58c 100644 --- a/lib/transaction/operation/congress_voting_result.go +++ b/lib/transaction/operation/congress_voting_result.go @@ -1,7 +1,6 @@ package operation import ( - "encoding/json" "strconv" "strings" @@ -61,9 +60,6 @@ func NewCongressVotingResult( } } -func (o CongressVotingResult) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} func (o CongressVotingResult) IsWellFormed(common.Config) (err error) { if len(o.BallotStamps.Hash) == 0 { return errors.OperationBodyInsufficient diff --git a/lib/transaction/operation/create_account.go b/lib/transaction/operation/create_account.go index 8c76f20ba..ee044e74e 100644 --- a/lib/transaction/operation/create_account.go +++ b/lib/transaction/operation/create_account.go @@ -1,8 +1,6 @@ package operation import ( - "encoding/json" - "boscoin.io/sebak/lib/common" "boscoin.io/sebak/lib/common/keypair" "boscoin.io/sebak/lib/errors" @@ -22,10 +20,6 @@ func NewCreateAccount(target string, amount common.Amount, linked string) Create } } -func (o CreateAccount) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} - // Implement transaction/operation : IsWellFormed func (o CreateAccount) IsWellFormed(common.Config) (err error) { if _, err = keypair.Parse(o.Target); err != nil { diff --git a/lib/transaction/operation/inflation.go b/lib/transaction/operation/inflation.go index 3a403f912..d0bc56818 100644 --- a/lib/transaction/operation/inflation.go +++ b/lib/transaction/operation/inflation.go @@ -1,7 +1,6 @@ package operation import ( - "encoding/json" "strings" "boscoin.io/sebak/lib/common" @@ -79,10 +78,6 @@ func (o Inflation) GetAmount() common.Amount { return o.Amount } -func (o Inflation) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} - func (o Inflation) HasFee() bool { return false } diff --git a/lib/transaction/operation/inflation_pf.go b/lib/transaction/operation/inflation_pf.go index f35aaf47c..0af04866c 100644 --- a/lib/transaction/operation/inflation_pf.go +++ b/lib/transaction/operation/inflation_pf.go @@ -1,7 +1,6 @@ package operation import ( - "encoding/json" "strconv" "strings" @@ -52,10 +51,6 @@ func (o InflationPF) GetAmount() common.Amount { return o.Amount } -func (o InflationPF) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} - func (o InflationPF) HasFee() bool { return false } diff --git a/lib/transaction/operation/operation.go b/lib/transaction/operation/operation.go index ffceddb90..b73a0be84 100644 --- a/lib/transaction/operation/operation.go +++ b/lib/transaction/operation/operation.go @@ -99,7 +99,6 @@ type Body interface { // An `error` if that transaction is invalid, `nil` otherwise // IsWellFormed(common.Config) error - Serialize() ([]byte, error) HasFee() bool } @@ -125,10 +124,6 @@ func (o Operation) IsWellFormed(conf common.Config) (err error) { return o.B.IsWellFormed(conf) } -func (o Operation) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} - func (o Operation) String() string { encoded, _ := json.MarshalIndent(o, "", " ") diff --git a/lib/transaction/operation/operation_test.go b/lib/transaction/operation/operation_test.go index 381a81a94..0e626ecbb 100644 --- a/lib/transaction/operation/operation_test.go +++ b/lib/transaction/operation/operation_test.go @@ -46,12 +46,11 @@ func TestIsWellFormedOperationLowerAmount(t *testing.T) { func TestSerializeOperation(t *testing.T) { op := MakeTestPayment(-1) - b, err := op.Serialize() - require.NoError(t, err) + b := common.MustMarshalJSON(op) require.Equal(t, len(b) > 0, true) var o Operation - err = json.Unmarshal(b, &o) + err := json.Unmarshal(b, &o) require.NoError(t, err) } diff --git a/lib/transaction/operation/payment.go b/lib/transaction/operation/payment.go index 97f4c286b..230f0a6c7 100644 --- a/lib/transaction/operation/payment.go +++ b/lib/transaction/operation/payment.go @@ -1,8 +1,6 @@ package operation import ( - "encoding/json" - "boscoin.io/sebak/lib/common" "boscoin.io/sebak/lib/common/keypair" "boscoin.io/sebak/lib/errors" @@ -20,10 +18,6 @@ func NewPayment(target string, amount common.Amount) Payment { } } -func (o Payment) Serialize() (encoded []byte, err error) { - return json.Marshal(o) -} - // Implement transaction/operation : IsWellFormed func (o Payment) IsWellFormed(common.Config) (err error) { if _, err = keypair.Parse(o.Target); err != nil { diff --git a/lib/transaction/operation/unfreezing_request.go b/lib/transaction/operation/unfreezing_request.go index 474c866c9..1da0f11eb 100644 --- a/lib/transaction/operation/unfreezing_request.go +++ b/lib/transaction/operation/unfreezing_request.go @@ -1,8 +1,6 @@ package operation import ( - "encoding/json" - "boscoin.io/sebak/lib/common" ) @@ -12,11 +10,6 @@ func NewUnfreezeRequest() UnfreezeRequest { return UnfreezeRequest{} } -func (o UnfreezeRequest) Serialize() (encoded []byte, err error) { - encoded, err = json.Marshal(o) - return -} - func (o UnfreezeRequest) IsWellFormed(common.Config) (err error) { return }