Skip to content

Commit

Permalink
Resolve cyclic dependency in intents package
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Dec 1, 2023
1 parent 084400d commit c39e106
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packets
package intents

import (
"encoding/json"
Expand All @@ -7,7 +7,7 @@ import (

"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/intents"
"github.com/0xsequence/go-sequence/intents/packets"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -90,7 +90,7 @@ func TestRecoverTransactionIntent(t *testing.T) {
]
}`

intent := &intents.Intent{}
intent := &Intent{}
err := json.Unmarshal([]byte(data), intent)
assert.Nil(t, err)

Expand All @@ -105,8 +105,8 @@ func TestRecoverTransactionIntent(t *testing.T) {
assert.Equal(t, 1, len(signers))
assert.Equal(t, "0x1111BD4F3233e7a7f552AdAf32C910fD30de598B", signers[0])

packet := &SendTransactionsPacket{}
err = packet.Unmarshal(intent)
packet := &packets.SendTransactionsPacket{}
err = packet.Unmarshal(intent.Packet)
assert.Nil(t, err)

assert.Equal(t, "sendTransaction", packet.Code)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packets
package intents

import (
"encoding/json"
Expand All @@ -7,7 +7,7 @@ import (

"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/intents"
"github.com/0xsequence/go-sequence/intents/packets"
"github.com/stretchr/testify/assert"
)

Expand All @@ -28,7 +28,7 @@ func TestRecoverMessageIntent(t *testing.T) {
}]
}`

intent := &intents.Intent{}
intent := &Intent{}
err := json.Unmarshal([]byte(data), intent)
assert.Nil(t, err)

Expand All @@ -43,8 +43,8 @@ func TestRecoverMessageIntent(t *testing.T) {
assert.Equal(t, 1, len(signers))
assert.Equal(t, "0x1111BD4F3233e7a7f552AdAf32C910fD30de598B", signers[0])

packet := &SignMessagePacket{}
err = packet.Unmarshal(intent)
packet := &packets.SignMessagePacket{}
err = packet.Unmarshal(intent.Packet)
assert.Nil(t, err)

assert.Equal(t, "signMessage", packet.Code)
Expand Down
6 changes: 2 additions & 4 deletions intents/packets/close_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package packets
import (
"encoding/json"
"fmt"

"github.com/0xsequence/go-sequence/intents"
)

type CloseSessionPacket struct {
Expand All @@ -14,8 +12,8 @@ type CloseSessionPacket struct {

const CloseSessionPacketCode = "closeSession"

func (p *CloseSessionPacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *CloseSessionPacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions intents/packets/finish_validate_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package packets
import (
"encoding/json"
"fmt"

"github.com/0xsequence/go-sequence/intents"
)

type FinishValidateSessionPacket struct {
Expand All @@ -16,8 +14,8 @@ type FinishValidateSessionPacket struct {

const FinishValidateSessionPacketCode = "finishValidateSession"

func (p *FinishValidateSessionPacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *FinishValidateSessionPacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions intents/packets/open_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package packets
import (
"encoding/json"
"fmt"

"github.com/0xsequence/go-sequence/intents"
)

type OpenSessionPacket struct {
Expand All @@ -20,8 +18,8 @@ type OpenSessionPacketProof struct {

const OpenSessionPacketCode = "openSession"

func (p *OpenSessionPacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *OpenSessionPacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions intents/packets/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/ethkit/go-ethereum/core/types"
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/intents"
"github.com/0xsequence/go-sequence/relayer/proto"
)

Expand All @@ -24,8 +23,8 @@ type SendTransactionsPacket struct {

const SendTransactionCode = "sendTransaction"

func (p *SendTransactionsPacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *SendTransactionsPacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions intents/packets/sign_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/intents"
)

type SignMessagePacket struct {
Expand All @@ -19,8 +18,8 @@ type SignMessagePacket struct {

const SignMessagePacketCode = "signMessage"

func (p *SignMessagePacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *SignMessagePacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down
10 changes: 4 additions & 6 deletions intents/packets/validate_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package packets
import (
"encoding/json"
"fmt"

"github.com/0xsequence/go-sequence/intents"
)

type ValidateSessionPacket struct {
Expand All @@ -16,8 +14,8 @@ type ValidateSessionPacket struct {

const ValidateSessionPacketCode = "validateSession"

func (p *ValidateSessionPacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *ValidateSessionPacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down Expand Up @@ -47,8 +45,8 @@ type GetSessionPacket struct {
Session string `json:"session"`
}

func (p *GetSessionPacket) Unmarshal(i *intents.Intent) error {
err := json.Unmarshal(i.Packet, &p)
func (p *GetSessionPacket) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}
Expand Down

0 comments on commit c39e106

Please sign in to comment.