Skip to content

Commit

Permalink
Fix json encoding/decoding of computational requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Nov 23, 2023
1 parent 4dcd881 commit e5efd28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 9 additions & 9 deletions core/types/transaction_marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type txJSON struct {
KettleAddress *common.Address `json:"kettleAddress,omitempty"`
ConfidentialInputsHash *common.Hash `json:"confidentialInputsHash,omitempty"`
ConfidentialInputs *hexutil.Bytes `json:"confidentialInputs,omitempty"`
Wrapped *json.RawMessage `json:"wrapped,omitempty"`
RequestRecord *json.RawMessage `json:"requestRecord,omitempty"`
ConfidentialComputeResult *hexutil.Bytes `json:"confidentialComputeResult,omitempty"`
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
Expand Down Expand Up @@ -148,12 +148,12 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
enc.S = (*hexutil.Big)(itx.S)

case *SuaveTransaction:
wrapped, err := NewTx(&itx.ConfidentialComputeRequest).MarshalJSON()
requestRecord, err := NewTx(&itx.ConfidentialComputeRequest).MarshalJSON()
if err != nil {
return nil, err
}

enc.Wrapped = (*json.RawMessage)(&wrapped)
enc.RequestRecord = (*json.RawMessage)(&requestRecord)

enc.ChainID = (*hexutil.Big)(itx.ChainID)
enc.ConfidentialComputeResult = (*hexutil.Bytes)(&itx.ConfidentialComputeResult)
Expand Down Expand Up @@ -396,7 +396,7 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
}

case ConfidentialComputeRecordTxType:
var itx ConfidentialComputeRequest
var itx ConfidentialComputeRecord
inner = &itx

if dec.KettleAddress == nil {
Expand Down Expand Up @@ -521,17 +521,17 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
var itx SuaveTransaction
inner = &itx

if dec.Wrapped == nil {
return errors.New("missing required field 'wrapped' in transaction")
if dec.RequestRecord == nil {
return errors.New("missing required field 'requestRecord' in transaction")
}

var wrappedTx Transaction
err := wrappedTx.UnmarshalJSON(([]byte)(*dec.Wrapped))
var requestRecord Transaction
err := requestRecord.UnmarshalJSON(([]byte)(*dec.RequestRecord))
if err != nil {
return err
}

ccr, ok := CastTxInner[*ConfidentialComputeRecord](&wrappedTx)
ccr, ok := CastTxInner[*ConfidentialComputeRecord](&requestRecord)
if !ok {
return errors.New("wrapped tx not a ConfidentialComputeRecord")
}
Expand Down
7 changes: 6 additions & 1 deletion suave/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,14 @@ func TestE2EPrecompile_Call(t *testing.T) {
sourceContract := sdk.GetContract(contractAddr, exampleCallSourceContract.Abi, clt)

expectedNum := big.NewInt(101)
_, err := sourceContract.SendTransaction("callTarget", []interface{}{contractAddr, expectedNum}, nil)
res, err := sourceContract.SendTransaction("callTarget", []interface{}{contractAddr, expectedNum}, nil)
require.NoError(t, err)

// make sure we can retrieve the transaction
tx, _, err := ethclient.NewClient(fr.suethSrv.RPCNode()).TransactionByHash(context.Background(), res.Hash())
require.NoError(t, err)
require.Equal(t, tx.Type(), uint8(types.SuaveTxType))

incorrectNum := big.NewInt(102)
_, err = sourceContract.SendTransaction("callTarget", []interface{}{contractAddr, incorrectNum}, nil)
require.Error(t, err)
Expand Down

0 comments on commit e5efd28

Please sign in to comment.