Skip to content

Commit

Permalink
implement non-working decode
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkouv committed Jul 11, 2024
1 parent 394e068 commit a339b42
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
72 changes: 70 additions & 2 deletions core/services/ocr3/plugins/ccipevm/executecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,76 @@ func (e *ExecutePluginCodecV1) Encode(ctx context.Context, report cciptypes.Exec
return e.executeReportEventInputs.PackValues([]interface{}{&evmReport})
}

func (e *ExecutePluginCodecV1) Decode(ctx context.Context, bytes []byte) (cciptypes.ExecutePluginReport, error) {
panic("implement me")
func (e *ExecutePluginCodecV1) Decode(ctx context.Context, encodedReport []byte) (cciptypes.ExecutePluginReport, error) {
unpacked, err := e.executeReportEventInputs.Unpack(encodedReport)
if err != nil {
return cciptypes.ExecutePluginReport{}, fmt.Errorf("unpack encoded report: %w", err)
}
if len(unpacked) != 1 {
return cciptypes.ExecutePluginReport{}, fmt.Errorf("unpacked report is empty")
}

evmReportRaw := abi.ConvertType(unpacked[0], []evm_2_evm_multi_offramp.InternalExecutionReportSingleChain{})
evmReport, is := evmReportRaw.([]evm_2_evm_multi_offramp.InternalExecutionReportSingleChain)
if !is {
return cciptypes.ExecutePluginReport{}, fmt.Errorf("got an unexpected report type %T", unpacked[0])
}

executeReport := cciptypes.ExecutePluginReport{
ChainReports: make([]cciptypes.ExecutePluginReportSingleChain, 0, len(evmReport)),
}

for _, evmChainReport := range evmReport {
proofs := make([]cciptypes.Bytes32, 0, len(evmChainReport.Proofs))
for _, proof := range evmChainReport.Proofs {
proofs = append(proofs, proof)
}

messages := make([]cciptypes.Message, 0, len(evmChainReport.Messages))
for _, evmMessage := range evmChainReport.Messages {
tokenAmounts := make([]cciptypes.RampTokenAmount, 0, len(evmMessage.TokenAmounts))
for _, tokenAmount := range evmMessage.TokenAmounts {
tokenAmounts = append(tokenAmounts, cciptypes.RampTokenAmount{
SourcePoolAddress: tokenAmount.SourcePoolAddress,
DestTokenAddress: tokenAmount.DestTokenAddress,
ExtraData: tokenAmount.ExtraData,
Amount: cciptypes.NewBigInt(tokenAmount.Amount),
})
}

message := cciptypes.Message{
Header: cciptypes.RampMessageHeader{
MessageID: evmMessage.Header.MessageId,
SourceChainSelector: cciptypes.ChainSelector(evmMessage.Header.SourceChainSelector),
DestChainSelector: cciptypes.ChainSelector(evmMessage.Header.DestChainSelector),
SequenceNumber: cciptypes.SeqNum(evmMessage.Header.SequenceNumber),
Nonce: evmMessage.Header.Nonce,
MsgHash: cciptypes.Bytes32{}, // <-- todo
OnRamp: cciptypes.Bytes{}, // <-- todo
},
Sender: evmMessage.Sender,
Data: evmMessage.Data,
Receiver: evmMessage.Receiver.Bytes(),
ExtraArgs: cciptypes.Bytes{}, // <-- todo
FeeToken: cciptypes.Bytes{}, // <-- todo
FeeTokenAmount: cciptypes.BigInt{}, // <-- todo
TokenAmounts: tokenAmounts,
}
messages = append(messages, message)
}

chainReport := cciptypes.ExecutePluginReportSingleChain{
SourceChainSelector: cciptypes.ChainSelector(evmChainReport.SourceChainSelector),
Messages: messages,
OffchainTokenData: evmChainReport.OffchainTokenData,
Proofs: proofs,
ProofFlagBits: cciptypes.NewBigInt(evmChainReport.ProofFlagBits),
}

executeReport.ChainReports = append(executeReport.ChainReports, chainReport)
}

return executeReport, nil
}

// Ensure ExecutePluginCodec implements the ExecutePluginCodec interface
Expand Down
11 changes: 0 additions & 11 deletions core/services/ocr3/plugins/ccipevm/executecodec_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ccipevm

import (
rand2 "crypto/rand"
"math/rand"
"testing"

Expand Down Expand Up @@ -54,16 +53,6 @@ var randomExecuteReport = func(t *testing.T) cciptypes.ExecutePluginReport {
}

tokenData := make([][][]byte, numTokensPerMsg)
for j := 0; j < msgsPerReport; j++ {
tokenData[j] = make([][]byte, numTokensPerMsg)
for z := 0; z < numTokensPerMsg; z++ {
tokenData[z] = make([][]byte, 32)
for k := 0; k < 32; k++ {
_, err := rand2.Read(tokenData[z][k])
assert.NoError(t, err)
}
}
}

chainReports[i] = cciptypes.ExecutePluginReportSingleChain{
SourceChainSelector: cciptypes.ChainSelector(rand.Uint64()),
Expand Down

0 comments on commit a339b42

Please sign in to comment.