generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SPV-1121): adjust op_return recording to domain services approach (
#874)
- Loading branch information
1 parent
9176446
commit 924bdb9
Showing
39 changed files
with
761 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
actions/v2/transactions/internal/mapping/recorded_outline.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mapping | ||
|
||
import ( | ||
"github.com/bitcoin-sv/spv-wallet/engine/v2/transaction/txmodels" | ||
"github.com/bitcoin-sv/spv-wallet/models/response" | ||
) | ||
|
||
// RecordedOutline maps domain RecordedOutline to response.RecordedOutline. | ||
func RecordedOutline(r *txmodels.RecordedOutline) response.RecordedOutline { | ||
return response.RecordedOutline{ | ||
TxID: r.TxID, | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
actions/v2/transactions/internal/mapping/transaction_outline.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package mapping | ||
|
||
import ( | ||
"maps" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/engine/v2/transaction" | ||
"github.com/bitcoin-sv/spv-wallet/engine/v2/transaction/outlines" | ||
"github.com/bitcoin-sv/spv-wallet/models/request" | ||
) | ||
|
||
// TransactionOutline maps request's AnnotatedTransaction to outlines.Transaction. | ||
func TransactionOutline(req *request.AnnotatedTransaction) *outlines.Transaction { | ||
return &outlines.Transaction{ | ||
BEEF: req.BEEF, | ||
Annotations: transaction.Annotations{ | ||
Outputs: maps.Collect(func(yield func(int, *transaction.OutputAnnotation) bool) { | ||
if req.Annotations == nil || len(req.Annotations.Outputs) == 0 { | ||
return | ||
} | ||
for index, output := range req.Annotations.Outputs { | ||
var paymail *transaction.PaymailAnnotation | ||
if output.Paymail != nil { | ||
paymail = &transaction.PaymailAnnotation{ | ||
Receiver: output.Paymail.Receiver, | ||
Reference: output.Paymail.Reference, | ||
Sender: output.Paymail.Sender, | ||
} | ||
} | ||
yield(index, &transaction.OutputAnnotation{ | ||
Bucket: output.Bucket, | ||
Paymail: paymail, | ||
}) | ||
} | ||
}), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package transactions | ||
|
||
import "github.com/bitcoin-sv/spv-wallet/server/handlers" | ||
import ( | ||
"github.com/bitcoin-sv/spv-wallet/server/handlers" | ||
routes "github.com/bitcoin-sv/spv-wallet/server/handlers" | ||
) | ||
|
||
// RegisterRoutes creates the specific package routes | ||
func RegisterRoutes(handlersManager *handlers.Manager) { | ||
if handlersManager.GetFeatureFlags().V2 { | ||
group := handlersManager.Group(handlers.GroupAPIV2, "/transactions") | ||
group.POST("/outlines", handlers.AsUser(transactionOutlines)) | ||
group.POST("", handlers.AsUser(transactionRecordOutline)) | ||
} | ||
func RegisterRoutes(handlersManager *routes.Manager) { | ||
group := handlersManager.Group(handlers.GroupAPIV2, "/transactions") | ||
group.POST("/outlines", handlers.AsUser(transactionOutlines)) | ||
group.POST("", handlers.AsUser(recordOutline)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package testabilities | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/engine" | ||
"github.com/bitcoin-sv/spv-wallet/engine/tester/fixtures" | ||
"github.com/bitcoin-sv/spv-wallet/engine/v2/transaction/txmodels" | ||
"github.com/bitcoin-sv/spv-wallet/models/bsv" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type faucetFixture struct { | ||
engine engine.ClientInterface | ||
user fixtures.User | ||
t testing.TB | ||
assert *assert.Assertions | ||
arc ARCFixture | ||
bhs BlockHeadersServiceFixture | ||
} | ||
|
||
func (f *faucetFixture) TopUp(satoshis bsv.Satoshis) fixtures.GivenTXSpec { | ||
f.t.Helper() | ||
|
||
txSpec := fixtures.GivenTX(f.t). | ||
WithSender(fixtures.ExternalFaucet). | ||
WithInput(uint64(satoshis + 1)). | ||
WithRecipient(f.user). | ||
WithP2PKHOutput(uint64(satoshis)) | ||
|
||
operation := txmodels.NewOperation{ | ||
UserID: f.user.ID(), | ||
|
||
Type: "incoming", | ||
Value: int64(satoshis), //nolint:gosec // This is a test fixture, values won't exceed int64 | ||
|
||
Transaction: &txmodels.NewTransaction{ | ||
ID: txSpec.ID(), | ||
TxStatus: txmodels.TxStatusMined, | ||
Outputs: []txmodels.NewOutput{ | ||
txmodels.NewOutputForP2PKH( | ||
bsv.Outpoint{TxID: txSpec.ID(), Vout: 0}, | ||
f.user.ID(), | ||
satoshis, | ||
nil, | ||
), | ||
}, | ||
}, | ||
} | ||
|
||
err := f.engine.Repositories().Operations.SaveAll(context.Background(), func(yield func(*txmodels.NewOperation) bool) { | ||
yield(&operation) | ||
}) | ||
f.assert.NoError(err) | ||
|
||
// Additional check - assertion if the top-up operation was saved correctly | ||
balance, err := f.engine.Repositories().Users.GetBalance(context.Background(), f.user.ID(), "bsv") | ||
f.assert.NoError(err) | ||
f.assert.GreaterOrEqual(balance, satoshis) | ||
|
||
return txSpec | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.