Skip to content
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
3 changes: 2 additions & 1 deletion ocp/data/intent/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func fromIntentModel(obj *intentModel) *intent.Record {
NativeAmount: obj.NativeAmount,
UsdMarketValue: obj.UsdMarketValue,

IsSwapBuy: obj.IsSwap,
IsSwapBuy: obj.IsSwap,
IsReturned: obj.IsReturned,
}

if len(record.ExternalDepositMetadata.ExchangeCurrency) == 0 {
Expand Down
3 changes: 3 additions & 0 deletions ocp/data/swap/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (s *store) Save(_ context.Context, data *swap.Record) error {

data.Version++

item.Nonce = data.Nonce
item.Blockhash = data.Blockhash
item.TransactionSignature = data.TransactionSignature
item.TransactionBlob = data.TransactionBlob
item.State = data.State
item.Version = data.Version
Expand Down
2 changes: 1 addition & 1 deletion ocp/data/swap/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (m *model) dbSave(ctx context.Context, db *sqlx.DB) error {

ON CONFLICT (swap_id)
DO UPDATE
SET transaction_blob = $15, state = $16, version = ` + tableName + `.version + 1
SET nonce = $11, blockhash = $12, transaction_signature = $14, transaction_blob = $15, state = $16, version = ` + tableName + `.version + 1
WHERE ` + tableName + `.swap_id = $1 AND ` + tableName + `.version = $17

RETURNING
Expand Down
23 changes: 23 additions & 0 deletions ocp/data/swap/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ func testUpdateHappyPath(t *testing.T, s swap.Store) {
actual, err = s.GetById(ctx, "test_swap_id")
require.NoError(t, err)
assertEquivalentRecords(t, expected, actual)

expected.Nonce = "rotated_nonce"
expected.Blockhash = "rotated_blockhash"
expected.TransactionSignature = "rotated_transaction_signature"
expected.TransactionBlob = []byte("rotated_transaction_blob")
expected.State = swap.StateCancelling
mutatedProof := expected.ProofSignature + "_should_be_ignored"
expected.ProofSignature = mutatedProof

err = s.Save(ctx, expected)
require.NoError(t, err)
assert.EqualValues(t, 1, expected.Id)
assert.EqualValues(t, 3, expected.Version)

actual, err = s.GetById(ctx, "test_swap_id")
require.NoError(t, err)
assert.Equal(t, "rotated_nonce", actual.Nonce)
assert.Equal(t, "rotated_blockhash", actual.Blockhash)
assert.Equal(t, "rotated_transaction_signature", actual.TransactionSignature)
assert.Equal(t, []byte("rotated_transaction_blob"), actual.TransactionBlob)
assert.Equal(t, swap.StateCancelling, actual.State)
assert.Equal(t, "test_proof_signature", actual.ProofSignature)
assert.NotEqual(t, mutatedProof, actual.ProofSignature)
})
}

Expand Down
21 changes: 18 additions & 3 deletions ocp/worker/swap/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
indexerpb "github.com/code-payments/code-vm-indexer/generated/indexer/v1"

ocp_data "github.com/code-payments/ocp-server/ocp/data"
"github.com/code-payments/ocp-server/ocp/data/nonce"
"github.com/code-payments/ocp-server/ocp/data/swap"
"github.com/code-payments/ocp-server/ocp/integration"
"github.com/code-payments/ocp-server/ocp/transaction"
"github.com/code-payments/ocp-server/ocp/worker"
)

Expand All @@ -21,17 +23,29 @@ type runtime struct {
data ocp_data.Provider
vmIndexerClient indexerpb.IndexerClient
integration integration.Swap
solanaNoncePool *transaction.LocalNoncePool
}

func New(log *zap.Logger, data ocp_data.Provider, vmIndexerClient indexerpb.IndexerClient, integration integration.Swap, configProvider ConfigProvider) worker.Runtime {
func New(
log *zap.Logger,
data ocp_data.Provider,
vmIndexerClient indexerpb.IndexerClient,
integration integration.Swap,
solanaNoncePool *transaction.LocalNoncePool,
configProvider ConfigProvider,
) (worker.Runtime, error) {
if err := solanaNoncePool.Validate(nonce.EnvironmentSolana, nonce.EnvironmentInstanceSolanaMainnet, nonce.PurposeOnDemandTransaction); err != nil {
return nil, err
}

return &runtime{
log: log,
conf: configProvider(),
data: data,
vmIndexerClient: vmIndexerClient,
integration: integration,
}

solanaNoncePool: solanaNoncePool,
}, nil
}

func (p *runtime) Start(ctx context.Context, interval time.Duration) error {
Expand All @@ -40,6 +54,7 @@ func (p *runtime) Start(ctx context.Context, interval time.Duration) error {
swap.StateFunding,
swap.StateFunded,
swap.StateSubmitting,
swap.StateCancelling,
} {
go func(state swap.State) {

Expand Down
Loading
Loading