diff --git a/pkg/internal/unit21/transaction_test.go b/pkg/internal/unit21/transaction_test.go index ebd28b52..74e4b6ad 100644 --- a/pkg/internal/unit21/transaction_test.go +++ b/pkg/internal/unit21/transaction_test.go @@ -168,12 +168,12 @@ func mockTransactionRows(mock sqlmock.Sqlmock, transaction model.Transaction, us AddRow(transaction.DestinationTxLegId, time.Now(), "1", transaction.TransactionAmount, assetId2, userId, instrumentId2) mock.ExpectQuery("SELECT * FROM tx_leg WHERE id = $1 AND deleted_at IS NULL").WithArgs(transaction.DestinationTxLegId).WillReturnRows(mockedTxLegRow2) - mockedAssetRow1 := sqlmock.NewRows([]string{"id", "name", "description", "decimals", "is_crypto", "network_id", "value_oracle"}). - AddRow(assetId1, "USD", "fiat USD", 6, false, transaction.NetworkId, "self") + mockedAssetRow1 := sqlmock.NewRows([]string{"id", "name", "description", "decimals", "is_crypto", "value_oracle"}). + AddRow(assetId1, "USD", "fiat USD", 6, false, "self") mock.ExpectQuery("SELECT * FROM asset WHERE id = $1 AND deleted_at IS NULL").WithArgs(assetId1).WillReturnRows(mockedAssetRow1) - mockedAssetRow2 := sqlmock.NewRows([]string{"id", "name", "description", "decimals", "is_crypto", "network_id", "value_oracle"}). - AddRow(assetId2, "Noose The Goose", "Noose the Goose NFT", 0, true, transaction.NetworkId, "joepegs.com") + mockedAssetRow2 := sqlmock.NewRows([]string{"id", "name", "description", "decimals", "is_crypto", "value_oracle"}). + AddRow(assetId2, "Noose The Goose", "Noose the Goose NFT", 0, true, "joepegs.com") mock.ExpectQuery("SELECT * FROM asset WHERE id = $1 AND deleted_at IS NULL").WithArgs(assetId2).WillReturnRows(mockedAssetRow2) mockedDeviceRow := sqlmock.NewRows([]string{"id", "type", "description", "fingerprint", "ip_addresses", "user_id"}). diff --git a/pkg/model/entity.go b/pkg/model/entity.go index 9ee42a26..092f7e7c 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -65,7 +65,6 @@ type Asset struct { Description string `json:"description" db:"description"` Decimals uint64 `json:"decimals" db:"decimals"` IsCrypto bool `json:"isCrypto" db:"is_crypto"` - NetworkId sql.NullString `json:"networkId" db:"network_id"` ValueOracle sql.NullString `json:"valueOracle" db:"value_oracle"` ValueOracle2 sql.NullString `json:"valueOracle2" db:"value_oracle_2"` } diff --git a/pkg/repository/asset.go b/pkg/repository/asset.go index 364f51b9..29664c9d 100644 --- a/pkg/repository/asset.go +++ b/pkg/repository/asset.go @@ -32,8 +32,16 @@ func (a asset[T]) Create(ctx context.Context, insert model.Asset) (model.Asset, m := model.Asset{} query, args, err := a.Named(` - INSERT INTO asset (name, description, decimals, is_crypto, network_id, value_oracle, value_oracle_2) - VALUES(:name, :description, :decimals, :is_crypto, :network_id, :value_oracle, :value_oracle_2) RETURNING *`, insert) + WITH insert_asset AS ( + INSERT INTO asset (name, description, decimals, is_crypto, value_oracle, value_oracle_2) + VALUES(:name, :description, :decimals, :is_crypto, :value_oracle, :value_oracle_2) + ON CONFLICT (name) DO NOTHING + RETURNING * + ) + INSERT INTO asset_to_network (asset_id, network_id) + VALUES(insert_asset.id, :network_id) + ON CONFLICT (asset_id, network_id) DO NOTHING + `, insert) if err != nil { return m, libcommon.StringError(err) diff --git a/pkg/service/transaction.go b/pkg/service/transaction.go index 830a4545..feea6f8a 100644 --- a/pkg/service/transaction.go +++ b/pkg/service/transaction.go @@ -737,7 +737,7 @@ func (t transaction) addWalletInstrumentIdIfNew(ctx context.Context, address str } // Create a new instrument - instrument = model.Instrument{Type: "crypto wallet", Status: "external", Network: "ethereum", PublicKey: address, UserId: id} // No locationId or userId because this wallet was not registered with the user and is some other recipient + instrument = model.Instrument{Type: "crypto wallet", Status: "external", Network: "EVM", PublicKey: address, UserId: id} // No locationId or userId because this wallet was not registered with the user and is some other recipient instrument, err = t.repos.Instrument.Create(ctx, instrument) if err != nil { return "", libcommon.StringError(err)