Skip to content

Commit 9b16f87

Browse files
authored
Merge pull request #185 from bsv-blockchain/fix/167-beef-isvalid
fix beef.IsValid
2 parents 82aedff + 4ae3cde commit 9b16f87

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. The format
44

55
## Table of Contents
66

7+
- [1.2.1 - 2025-06-12](#121---2025-06-12)
78
- [1.2.0 - 2025-06-10](#120---2025-06-10)
89
- [1.1.27 - 2025-05-15](#1127---2025-05-15)
910
- [1.1.26 - 2025-05-14](#1126---2025-05-14)
@@ -35,6 +36,15 @@ All notable changes to this project will be documented in this file. The format
3536
- [1.1.0 - 2024-08-19](#110---2024-08-19)
3637
- [1.0.0 - 2024-06-06](#100---2024-06-06)
3738

39+
## [1.2.1] - 2025-06-12
40+
41+
### Added
42+
- New `NewBeefFromHex` convenience function to create BEEF transactions directly from hex strings
43+
44+
### Fixed
45+
- Fixed BEEF `IsValid` verification to properly handle transactions without MerklePath data
46+
- Corrected validation logic in `verifyValid` to check for MerklePath existence before validating transaction inputs
47+
3848
## [1.2.0] - 2025-06-10
3949

4050
This is a major release introducing comprehensive new modules for authentication, key-value storage, overlay services, registry management, decentralized storage, and advanced wallet functionality. This release represents a significant architectural evolution of the SDK, aligning with the TypeScript SDK's capabilities.

transaction/beef.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ func readBeefTx(reader *bytes.Reader, BUMPs []*MerklePath) (*map[string]*BeefTx,
123123
return &txs, nil
124124
}
125125

126+
func NewBeefFromHex(beefHex string) (*Beef, error) {
127+
beef, err := hex.DecodeString(beefHex)
128+
if err != nil {
129+
return nil, fmt.Errorf("failed to decode beef hex: %w", err)
130+
}
131+
return NewBeefFromBytes(beef)
132+
}
133+
126134
func NewBeefFromBytes(beef []byte) (*Beef, error) {
127135
var reader *bytes.Reader
128136
if binary.LittleEndian.Uint32(beef[:4]) == ATOMIC_BEEF {
@@ -930,7 +938,7 @@ func (b *Beef) verifyValid(allowTxidOnly bool) verifyResult {
930938
}
931939

932940
for txid, beefTx := range b.Transactions {
933-
if beefTx.DataFormat != TxIDOnly {
941+
if beefTx.DataFormat != TxIDOnly && beefTx.Transaction.MerklePath == nil {
934942
for _, in := range beefTx.Transaction.Inputs {
935943
if !txids[in.SourceTXID.String()] {
936944
return r
@@ -1034,10 +1042,10 @@ func (b *Beef) trimUnreferencedBumps() {
10341042

10351043
// Track which BUMP indices are still referenced by remaining transactions
10361044
usedBumpIndices := make(map[int]bool)
1037-
1045+
10381046
// Build a set of transaction IDs that need BUMPs
10391047
txidsNeedingBumps := make(map[string]bool)
1040-
1048+
10411049
for txid, tx := range b.Transactions {
10421050
switch tx.DataFormat {
10431051
case RawTxAndBumpIndex:

transaction/beef_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ func TestBeefFromV1(t *testing.T) {
11571157
beef, err := NewBeefFromBytes(beefData)
11581158
require.NoError(t, err)
11591159
require.NotNil(t, beef)
1160+
require.True(t, beef.IsValid(false), "BEEF should be valid")
11601161
}
11611162

11621163
func TestBEEFGeneratedFromComplexTransactionTree2(t *testing.T) {

0 commit comments

Comments
 (0)