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 encoding/decoding of computational requests #108

Merged
merged 1 commit into from
Nov 23, 2023
Merged
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
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
Loading