Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix json unmarshalling error #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/graphql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Block struct {

type Transaction struct {
Hash types.Hash
Status string
Status types.HexNumber
Index uint64
Nonce types.HexNumber
From Address
Expand Down
2 changes: 1 addition & 1 deletion core/monitor/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (tm *DefaultTransactionMonitor) fetchTransaction(block *types.Block, hash t

tx := &types.Transaction{
Hash: hash,
Status: txOrigin.Status == "0x1",
Status: txOrigin.Status == 1,
BlockNumber: block.Number,
BlockHash: block.Hash,
Index: txOrigin.Index,
Expand Down
25 changes: 18 additions & 7 deletions types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,29 @@ func (num HexNumber) MarshalJSON() ([]byte, error) {
}

func (num *HexNumber) UnmarshalJSON(input []byte) error {
// check for integer first
var unwrappedUint uint64
var unwrapped string
if err := json.Unmarshal(input, &unwrapped); err != nil {
return err
}
out, err := strconv.ParseUint(unwrapped, 0, 64)
if err != nil {
return err
if err:= json.Unmarshal(input,&unwrappedUint); err!=nil{
//check for string later
if err := json.Unmarshal(input, &unwrapped); err != nil {
return err
}
//String if fine
out, err := strconv.ParseUint(unwrapped, 0, 64)
if err != nil {
return err
}
// returning number from String
*num = HexNumber(out)
return nil
}
*num = HexNumber(out)
// returning number from number
*num = HexNumber(unwrappedUint)
return nil
}


func (num *HexNumber) ToUint64() uint64 {
return uint64(*num)
}