Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

feat(BUX-368): arc callbacks #564

Closed
wants to merge 13 commits into from
Closed
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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ go.list
# Jetbrains
.idea/

#VSCode
.vscode/

# Eclipse
.project

Expand Down
116 changes: 0 additions & 116 deletions action_blockheader.go

This file was deleted.

18 changes: 5 additions & 13 deletions action_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import (
"context"
"database/sql"
"time"

"github.com/mrz1836/go-datastore"
customTypes "github.com/mrz1836/go-datastore/custom_types"
)

// NewDestination will get a new destination for an existing xPub
//
// xPubKey is the raw public xPub
func (c *Client) NewDestination(ctx context.Context, xPubKey string, chain uint32,
destinationType string, monitor bool, opts ...ModelOps) (*Destination, error) {
destinationType string, opts ...ModelOps) (*Destination, error) {

// Check for existing NewRelic transaction
ctx = c.GetOrStartTxn(ctx, "new_destination")
Expand All @@ -39,13 +35,6 @@
return nil, err
}

if monitor {
destination.Monitor = customTypes.NullTime{NullTime: sql.NullTime{
Valid: true,
Time: time.Now(),
}}
}

// Save the destination
if err = destination.Save(ctx); err != nil {
return nil, err
Expand All @@ -57,7 +46,7 @@

// NewDestinationForLockingScript will create a new destination based on a locking script
func (c *Client) NewDestinationForLockingScript(ctx context.Context, xPubID, lockingScript string,
monitor bool, opts ...ModelOps) (*Destination, error) {
opts ...ModelOps) (*Destination, error) {

// Check for existing NewRelic transaction
ctx = c.GetOrStartTxn(ctx, "new_destination_for_locking_script")
Expand All @@ -77,6 +66,7 @@
return nil, ErrUnknownLockingScript
}

<<<<<<< HEAD

Check failure on line 69 in action_destination.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

syntax error: unexpected <<, expected }

Check failure on line 69 in action_destination.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

syntax error: unexpected <<, expected }
// set the monitoring, passed down from the initiating function
// this will be set when calling NewDestination from http, but not for instance paymail
if monitor {
Expand All @@ -86,6 +76,8 @@
}}
}

=======
>>>>>>> 06feaba (feat(BUX-417): remove monitor, ITC flag and IncomingTransaction (#532))

Check failure on line 80 in action_destination.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

invalid character U+0023 '#'

Check failure on line 80 in action_destination.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

invalid character U+0023 '#'
// Save the destination
if err := destination.Save(ctx); err != nil {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions action_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestination() {

var destination *Destination
destination, err = tc.client.NewDestination(
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, false, opts...,
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, opts...,
)
assert.NoError(t, err)
assert.Equal(t, "fc1e635d98151c6008f29908ee2928c60c745266f9853e945c917b1baa05973e", destination.ID)
Expand All @@ -42,7 +42,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestination() {
assert.Equal(t, "test-value", destination.Metadata["test-key"])

destination2, err2 := tc.client.NewDestination(
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, false, opts...,
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, opts...,
)
assert.NoError(t, err2)
assert.Equal(t, testXPubID, destination2.XpubID)
Expand All @@ -65,7 +65,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestination() {

destination, err := tc.client.NewDestination(
context.Background(), testXPub, utils.ChainExternal,
utils.ScriptTypePubKeyHash, false, opts...,
utils.ScriptTypePubKeyHash, opts...,
)
require.Error(t, err)
require.Nil(t, destination)
Expand Down Expand Up @@ -99,7 +99,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestinationForLockingScript() {

var destination *Destination
destination, err = tc.client.NewDestinationForLockingScript(
tc.ctx, testXPubID, lockingScript, false, opts...,
tc.ctx, testXPubID, lockingScript, opts...,
)
assert.NoError(t, err)
assert.Equal(t, "a64c7aca7110c7cde92245252a58bb18a4317381fc31fc293f6aafa3fcc7019f", destination.ID)
Expand All @@ -118,7 +118,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestinationForLockingScript() {
opts := append(tc.client.DefaultModelOptions(), WithMetadatas(metadata))

destination, err := tc.client.NewDestinationForLockingScript(
tc.ctx, testXPubID, "", false,
tc.ctx, testXPubID, "",
opts...,
)
require.Error(t, err)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinations() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -176,7 +176,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinations() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -212,7 +212,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByAddress() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -240,7 +240,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByAddress() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -276,7 +276,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByLockingScript() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -305,7 +305,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByLockingScript() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -340,7 +340,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_UpdateDestinationMetadata() {
opts := tc.client.DefaultModelOptions()
opts = append(opts, WithMetadatas(metadata))
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down
43 changes: 36 additions & 7 deletions action_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/utils"
"github.com/bitcoin-sv/go-broadcast-client/broadcast"
"github.com/libsv/go-bc"
"github.com/libsv/go-bt"
"github.com/mrz1836/go-datastore"
)
Expand Down Expand Up @@ -46,13 +48,7 @@ func (c *Client) RecordRawTransaction(ctx context.Context, txHex string,
) (*Transaction, error) {
ctx = c.GetOrStartTxn(ctx, "record_raw_transaction")

allowUnknown := true
monitor := c.options.chainstate.Monitor()
if monitor != nil {
allowUnknown = monitor.AllowUnknownTransactions()
}

return saveRawTransaction(ctx, c, allowUnknown, txHex, opts...)
return saveRawTransaction(ctx, c, true, txHex, opts...)
}

// NewTransaction will create a new draft transaction and return it
Expand Down Expand Up @@ -387,6 +383,39 @@ func (c *Client) RevertTransaction(ctx context.Context, id string) error {
return err
}

// UpdateTransaction will update the broadcast callback transaction info, like: block height, block hash, status, bump.
func (c *Client) UpdateTransaction(ctx context.Context, callbackResp *broadcast.SubmittedTx) error {
bump, err := bc.NewBUMPFromStr(callbackResp.MerklePath)
if err != nil {
c.options.logger.Err(err).Msgf("failed to parse merkle path from broadcast callback - tx: %v", callbackResp)
return err
}

txInfo := &chainstate.TransactionInfo{
BlockHash: callbackResp.BlockHash,
BlockHeight: callbackResp.BlockHeight,
ID: callbackResp.TxID,
TxStatus: callbackResp.TxStatus,
BUMP: bump,
// it's not possible to get confirmations from broadcast client; zero would be treated as "not confirmed" that's why -1
Confirmations: -1,
}

tx, err := c.GetTransaction(ctx, "", txInfo.ID)
if err != nil {
c.options.logger.Err(err).Msgf("failed to get transaction by id: %v", txInfo.ID)
return err
}

syncTx, err := GetSyncTransactionByTxID(ctx, txInfo.ID, c.DefaultModelOptions()...)
if err != nil {
c.options.logger.Err(err).Msgf("failed to get sync transaction by tx id: %v", txInfo.ID)
return err
}

return processSyncTxSave(ctx, txInfo, syncTx, tx)
}

func generateTxIDFilterConditions(txIDs []string) *map[string]interface{} {
orConditions := make([]map[string]interface{}, len(txIDs))

Expand Down
4 changes: 2 additions & 2 deletions bux_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package bux
import (
"context"
"fmt"
"github.com/rs/zerolog"
"sync"
"testing"
"time"

"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/logging"
"github.com/BuxOrg/bux/taskmanager"
"github.com/BuxOrg/bux/tester"
"github.com/DATA-DOG/go-sqlmock"
Expand Down Expand Up @@ -68,7 +68,7 @@ type EmbeddedDBTestSuite struct {
func (ts *EmbeddedDBTestSuite) serveMySQL() {
defer ts.wg.Done()

logger := logging.GetDefaultLogger()
logger := zerolog.Nop()

for {
err := ts.MySQLServer.Start()
Expand Down
Loading
Loading