Skip to content

Commit

Permalink
Merge pull request #1723 from nspcc-dev/fix/rpcnumber
Browse files Browse the repository at this point in the history
Marshal fees and GAS as integers.
  • Loading branch information
roman-khimov authored Feb 10, 2021
2 parents 7c419ce + 18911ca commit 29b1581
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 58 deletions.
7 changes: 3 additions & 4 deletions pkg/core/state/notification_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"

"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
Expand Down Expand Up @@ -184,7 +183,7 @@ type Execution struct {
type executionAux struct {
Trigger string `json:"trigger"`
VMState string `json:"vmstate"`
GasConsumed fixedn.Fixed8 `json:"gasconsumed,string"`
GasConsumed int64 `json:"gasconsumed,string"`
Stack json.RawMessage `json:"stack"`
Events []NotificationEvent `json:"notifications"`
FaultException string `json:"exception,omitempty"`
Expand Down Expand Up @@ -212,7 +211,7 @@ func (e Execution) MarshalJSON() ([]byte, error) {
return json.Marshal(&executionAux{
Trigger: e.Trigger.String(),
VMState: e.VMState.String(),
GasConsumed: fixedn.Fixed8(e.GasConsumed),
GasConsumed: e.GasConsumed,
Stack: st,
Events: e.Events,
FaultException: e.FaultException,
Expand Down Expand Up @@ -253,7 +252,7 @@ func (e *Execution) UnmarshalJSON(data []byte) error {
}
e.VMState = state
e.Events = aux.Events
e.GasConsumed = int64(aux.GasConsumed)
e.GasConsumed = aux.GasConsumed
e.FaultException = aux.FaultException
return nil
}
16 changes: 1 addition & 15 deletions pkg/core/state/notification_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,7 @@ func TestMarshalUnmarshalJSONAppExecResult(t *testing.T) {
Events: []NotificationEvent{},
},
}

data, err := json.Marshal(appExecResult)
require.NoError(t, err)
expected := `{
"container":"0x` + appExecResult.Container.StringLE() + `",
"trigger":"Application",
"vmstate":"HALT",
"gasconsumed":"0.0000001",
"stack":[],
"notifications":[]
}`
require.JSONEq(t, expected, string(data))
actual := new(AppExecResult)
require.NoError(t, json.Unmarshal(data, actual))
require.Equal(t, appExecResult, actual)
testserdes.MarshalUnmarshalJSON(t, appExecResult, new(AppExecResult))
})

t.Run("positive, fault state", func(t *testing.T) {
Expand Down
33 changes: 16 additions & 17 deletions pkg/core/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
)
Expand Down Expand Up @@ -302,18 +301,18 @@ func (t *Transaction) Sender() util.Uint160 {
// transactionJSON is a wrapper for Transaction and
// used for correct marhalling of transaction.Data
type transactionJSON struct {
TxID util.Uint256 `json:"hash"`
Size int `json:"size"`
Version uint8 `json:"version"`
Nonce uint32 `json:"nonce"`
Sender string `json:"sender"`
SystemFee fixedn.Fixed8 `json:"sysfee"`
NetworkFee fixedn.Fixed8 `json:"netfee"`
ValidUntilBlock uint32 `json:"validuntilblock"`
Attributes []Attribute `json:"attributes"`
Signers []Signer `json:"signers"`
Script []byte `json:"script"`
Scripts []Witness `json:"witnesses"`
TxID util.Uint256 `json:"hash"`
Size int `json:"size"`
Version uint8 `json:"version"`
Nonce uint32 `json:"nonce"`
Sender string `json:"sender"`
SystemFee int64 `json:"sysfee,string"`
NetworkFee int64 `json:"netfee,string"`
ValidUntilBlock uint32 `json:"validuntilblock"`
Attributes []Attribute `json:"attributes"`
Signers []Signer `json:"signers"`
Script []byte `json:"script"`
Scripts []Witness `json:"witnesses"`
}

// MarshalJSON implements json.Marshaler interface.
Expand All @@ -329,8 +328,8 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
Signers: t.Signers,
Script: t.Script,
Scripts: t.Scripts,
SystemFee: fixedn.Fixed8(t.SystemFee),
NetworkFee: fixedn.Fixed8(t.NetworkFee),
SystemFee: t.SystemFee,
NetworkFee: t.NetworkFee,
}
return json.Marshal(tx)
}
Expand All @@ -347,8 +346,8 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
t.Attributes = tx.Attributes
t.Signers = tx.Signers
t.Scripts = tx.Scripts
t.SystemFee = int64(tx.SystemFee)
t.NetworkFee = int64(tx.NetworkFee)
t.SystemFee = tx.SystemFee
t.NetworkFee = tx.NetworkFee
t.Script = tx.Script
if t.Hash() != tx.TxID {
return errors.New("txid doesn't match transaction hash")
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/transaction/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func TestUnmarshalNeoFSTX(t *testing.T) {
"version": 0,
"nonce": 737880259,
"sender": "NiRqSd5MtRZT5yUhgWd7oG11brkDG76Jim",
"sysfee": "2.2371942",
"netfee": "0.0121555",
"sysfee": "223719420",
"netfee": "1215550",
"validuntilblock": 1931,
"attributes": [],
"signers": [
Expand Down
Loading

0 comments on commit 29b1581

Please sign in to comment.