Skip to content

Commit 8098190

Browse files
authored
Merge pull request #171 from bsv-blockchain/fix/atomic-beef
Fix atomic beef
2 parents d749ba3 + b9afa8a commit 8098190

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

55
## Table of Contents
6-
7-
- [1.1.25 - 2025-05-09](#1124---2025-05-09)
8-
- [1.1.24 - 2025-04-24](#1123---2025-04-29)
6+
- [1.1.26 - 2025-05-14](#1126---2025-05-14)
7+
- [1.1.25 - 2025-05-09](#1125---2025-05-09)
8+
- [1.1.24 - 2025-04-24](#1124---2025-04-29)
99
- [1.1.23 - 2025-04-23](#1123---2025-04-23)
1010
- [1.1.22 - 2025-03-14](#1122---2025-03-14)
1111
- [1.1.21 - 2025-03-12](#1121---2025-03-12)
@@ -32,6 +32,10 @@ All notable changes to this project will be documented in this file. The format
3232
- [1.1.0 - 2024-08-19](#110---2024-08-19)
3333
- [1.0.0 - 2024-06-06](#100---2024-06-06)
3434

35+
## [1.1.26] - 2025-05-14
36+
### Updated
37+
- Support AtomicBeef in NewBeefFromBytes
38+
3539
## [1.1.25] - 2025-05-09
3640
### Fix
3741
- nill pointer

transaction/beef.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ func readBeefTx(reader *bytes.Reader, BUMPs []*MerklePath) (*map[string]*BeefTx,
103103
sourceTxid := input.SourceTXID.String()
104104
if sourceObj, ok := txs[sourceTxid]; ok {
105105
input.SourceTransaction = sourceObj.Transaction
106-
} else if beefTx.Transaction.MerklePath == nil && beefTx.KnownTxID == nil {
107-
return nil, fmt.Errorf("reference to unknown txid in bump: %s", sourceTxid)
108106
}
109107
}
110108

@@ -117,8 +115,12 @@ func readBeefTx(reader *bytes.Reader, BUMPs []*MerklePath) (*map[string]*BeefTx,
117115
}
118116

119117
func NewBeefFromBytes(beef []byte) (*Beef, error) {
120-
reader := bytes.NewReader(beef)
121-
118+
var reader *bytes.Reader
119+
if binary.LittleEndian.Uint32(beef[:4]) == ATOMIC_BEEF {
120+
reader = bytes.NewReader(beef[36:])
121+
} else {
122+
reader = bytes.NewReader(beef)
123+
}
122124
version, err := readVersion(reader)
123125
if err != nil {
124126
return nil, err

transaction/beef_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,19 @@ func TestNewBEEFFromBytes(t *testing.T) {
9696
require.Len(t, beef.BUMPs, 3, "BUMPs length does not match")
9797
require.Len(t, beef.Transactions, 3, "Transactions length does not match")
9898

99+
tx := beef.FindTransaction("b1fc0f44ba629dbdffab9e34fcc4faf9dbde3560a7365c55c26fe4daab052aac")
100+
require.NotNil(t, tx, "Transaction not found in BEEF data")
101+
102+
atomic, err := tx.AtomicBEEF(false)
103+
require.NoError(t, err, "AtomicBEEF method failed")
104+
105+
_, err = NewTransactionFromBEEF(atomic)
106+
require.NoError(t, err, "NewTransactionFromBEEF method failed")
107+
99108
binary.LittleEndian.PutUint32(beefBytes[0:4], 0xdeadbeef)
100109
_, err = NewTransactionFromBEEF(beefBytes)
101110
require.Error(t, err, "use NewBeefFromBytes to parse anything which isn't V1 BEEF or AtomicBEEF")
111+
102112
}
103113

104114
func TestBeefTransactionFinding(t *testing.T) {

0 commit comments

Comments
 (0)