Skip to content

Commit

Permalink
Merge pull request #52 from BitcoinSchema/update/ord
Browse files Browse the repository at this point in the history
breaking change: NewFromTx -> NewFromRawTxString
  • Loading branch information
rohenaz authored Mar 18, 2023
2 parents 6c31651 + 5e78b10 commit bf71f01
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
17 changes: 15 additions & 2 deletions bmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/bitcoinschema/go-boost"
"github.com/bitcoinschema/go-bpu"
magic "github.com/bitcoinschema/go-map"
"github.com/libsv/go-bt/v2"
)

// Tx is a Bmap formatted tx
Expand All @@ -35,8 +36,20 @@ func NewFromBob(bobTx *bob.Tx) (bmapTx *Tx, err error) {
return
}

// NewFromTx returns a new BmapTx from a hex string
func NewFromTx(tx string) (bmapTx *Tx, err error) {
// NewFromTx returns a new BmapTx from a a *bt.Tx
func NewFromTx(tx *bt.Tx) (bmapTx *Tx, err error) {
var bobTx *bob.Tx
if bobTx, err = bob.NewFromTx(tx); err != nil {
return
}

bmapTx = new(Tx)
err = bmapTx.FromBob(bobTx)
return
}

// NewFromRawTxString returns a new BmapTx from a hex string
func NewFromRawTxString(tx string) (bmapTx *Tx, err error) {
var bobTx *bob.Tx
if bobTx, err = bob.NewFromRawTxString(tx); err != nil {
return
Expand Down
26 changes: 21 additions & 5 deletions bmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/bitcoinschema/go-bob"
"github.com/bitcoinschema/go-bpu"
magic "github.com/bitcoinschema/go-map"
"github.com/libsv/go-bt/v2"
)

var cryptofights = "cryptofights"
var something = "something"
var tpowStr = "tonicpow"

func TestFromBob(t *testing.T) {

Expand Down Expand Up @@ -46,15 +48,15 @@ func TestFromTx(t *testing.T) {

t.Run("error", func(t *testing.T) {
tx := ""
_, err := NewFromTx(tx)
_, err := NewFromRawTxString(tx)
if err == nil {
t.Fatalf("error should occur")
}
})

t.Run("success", func(t *testing.T) {
tx := "01000000018952fe8892c429e69feb9b2dd9cd1f12ed757dc62e8d628b5a215f78ed895374020000006a47304402204784632fabca0f4aaa05dd6983633b2e8bf708d8766d0385f3393fff0623b88c02201a760e144116d47967501c2ea50dc231ae57c0eb78769d63713ce0648025c820412103221cb24c4e8b05a58bcf2ee8411f62e337c8099c8646babd47d0960899f69acaffffffff04680b0000000000001976a91409cc4559bdcb84cb35c107743f0dbb10d66679cc88ac0f720000000000001976a9146b1fe7b2063aa07766c764c0796fd4efd00340f288ac8a893b00000000001976a914be5f62df829ef754b8be09b37b04c4e7f9ff59d588ac0000000000000000ad006a223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540361707008746f6e6963706f7704747970650b6f666665725f636c69636b0f6f666665725f636f6e6669675f696403383038106f666665725f73657373696f6e5f6964403464303537386561643432393266653163643163393936643931623534613130653333653334623031396231386330613564353730376461346461346437653900000000"
bmapData, err := NewFromTx(tx)
bmapData, err := NewFromRawTxString(tx)
if err != nil {
t.Fatalf("error occurred: %s", err)
}
Expand All @@ -64,14 +66,14 @@ func TestFromTx(t *testing.T) {
}

mapData := bmapData.MAP
if mapData[0]["app"] != "tonicpow" {
if mapData[0]["app"] != tpowStr {
t.Fatalf("test fromTx failed %+v", mapData)
}
})

t.Run("run + non standard", func(t *testing.T) {
tx := "01000000023df0e0c5933a28f8a60572588aa2073ebe6297b48e3196e2c404a6869e45eb0d020000006b483045022100e349bcbf4002426a472daf2c02921c7a98d01f5462ae66eaf2bac0973a37033a02203c35870bcf7febbbe5e75a90a86918153eea8b8976f5546871b50c7674c9c1154121024ee11d705c041678b7fe9b34490c099fb7ae915e4267ecbe290874f0fc1863b3ffffffff4e32d8d868b6fd280b7af6a70e008f0c05f769b5263ff81c63092ec32a8ba159040000006a47304402203f8236b23b50f758dad4522acb793f73305aa1efda1ab7b305facf09665eae91022049366bad7e887aecd45f2cdafec4a3b21c3f880431fe142809450981881fcf7b41210361e9371c81d97f869d51e6909eb1132fc6c55b2caa8c4cea6d06a4f99b446decffffffff0422020000000000001976a9145a468879d2c7f3d48e6664a76286c96653a8ed4488ac0000000000000000fd9d03006a0372756e01050972656c6179782e696f4d88037b22696e223a312c22726566223a5b22643631373030323561363232343864386466366463313465333830366536386238646633643830346338303063376266623233623062343233323836323530355f6f31222c22656162396666366464316165383230363535343635356537653130613766323161613039653232613462386634643034386661353431633137393764633735655f6f31222c22373261363165623939306666646236623338653566393535653139346665643566663662303134663735616336383233353339636535363133616561306265385f6f31222c22373237653762343233623765653430633062356265383766626137666135363733656132643230613734323539303430613732393564396333326139303031315f6f31222c22383162636566323962306534656437343566333432326330623736346133336337366430333638616632643265376464313339646238653030656533643861365f6f31222c22343931343536393336373661663735363765626532303637316335636230313336396163373838633230663362316338303466363234613165646131386633665f6f31222c22336237656634313131383562626533643031636165616462653666313135623031303361353436633465663061633734373461613666626237316166663230385f6f31225d2c226f7574223a5b2230323164363634333831613532306434636439383732373638333866356339336661353763393835626631356134633739656537633932643931396437373263225d2c2264656c223a5b2237306163303437613037383638643562636538333130633530383637623631313639373534346134386165353161353931356339643163636536303766383236225d2c22637265223a5b7b2224617262223a7b2261646472657373223a2231424b4475665758434b6672714b6e75465664524668554d4a4733654c6b77483767222c227361746f73686973223a31343030303030307d2c2254223a7b22246a6967223a317d7d5d2c2265786563223a5b7b226f70223a2243414c4c222c2264617461223a5b7b22246a6967223a307d2c2273656e64222c5b7b2224617262223a7b2261646472657373223a2231424b4475665758434b6672714b6e75465664524668554d4a4733654c6b77483767222c227361746f73686973223a31343030303030307d2c2254223a7b22246a6967223a317d7d2c355d5d7d5d7d8705000000000000fd100320b88bf03d21d88541df8c758a1da474c783f7c362c9daf2670229d9d55ef8226a01c35279630142517a75547901687f7501447f77007901207f7504000000007e517951797e56797eaa577901247f75547f77876975756754795579827758947f75557982770128947f77527987696861547921cdb285cc49e5ff3eed6536e7b426e8a528b05bf9276bd05431a671743e651ceb002102dca1e194dd541a47f4c85fea6a4d45bb50f16ed2fddc391bf80b525454f8b40920f941a26b1c1802eaa09109701e4e632e1ef730b0b68c9517e7c19be2ba4c7d37202f282d163597a82d72c263b004695297aecb4d758dccd1dbf61e82a3360bde2c202cde0b36a3821ef6dbd1cc8d754dcbae97526904b063c2722da89735162d282f56795679aa616100790079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a756157795679567956795679537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff0061517951795179517997527a75517a5179009f635179517993527a75517a685179517a75517a7561527a75517a517951795296a0630079527994527a75517a68537982775279827754527993517993013051797e527e53797e57797e527e52797e5579517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7e56797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561777777777738a20100000000001976a914f4993778efa9207d8f2670348c197dffdfe4f32f88ac00000000"
bmapData, err := NewFromTx(tx)
bmapData, err := NewFromRawTxString(tx)
if err != nil {
t.Fatalf("error occurred: %s", err)
}
Expand Down Expand Up @@ -123,11 +125,25 @@ func TestMapFromRawTxString(t *testing.T) {
m, err := magic.NewFromTape(&bob.Out[3].Tape[1])
if err != nil {
t.Fatalf("error occurred: %s", err)
} else if m["CMD"] != "SET" && m["app"] != "tonicpow" {
} else if m["CMD"] != "SET" && m["app"] != tpowStr {
t.Fatalf("SET Failed %v", m)
}
}

func TestMapFromTx(t *testing.T) {
tx, err := bt.NewTxFromString(`01000000018952fe8892c429e69feb9b2dd9cd1f12ed757dc62e8d628b5a215f78ed895374020000006a47304402204784632fabca0f4aaa05dd6983633b2e8bf708d8766d0385f3393fff0623b88c02201a760e144116d47967501c2ea50dc231ae57c0eb78769d63713ce0648025c820412103221cb24c4e8b05a58bcf2ee8411f62e337c8099c8646babd47d0960899f69acaffffffff04680b0000000000001976a91409cc4559bdcb84cb35c107743f0dbb10d66679cc88ac0f720000000000001976a9146b1fe7b2063aa07766c764c0796fd4efd00340f288ac8a893b00000000001976a914be5f62df829ef754b8be09b37b04c4e7f9ff59d588ac0000000000000000ad006a223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540361707008746f6e6963706f7704747970650b6f666665725f636c69636b0f6f666665725f636f6e6669675f696403383038106f666665725f73657373696f6e5f6964403464303537386561643432393266653163643163393936643931623534613130653333653334623031396231386330613564353730376461346461346437653900000000`)
if err != nil {
t.Fatalf("error occurred: %s", err)
}

bmapTx, err := NewFromTx(tx)
if err != nil {
t.Fatalf("error occurred: %s", err)
} else if bmapTx.MAP[0]["CMD"] != "SET" && bmapTx.MAP[0]["app"] != tpowStr {
t.Fatalf("SET Failed %v", bmapTx)
}
}

func TestRun(t *testing.T) {
r := "run"
zero5 := "05"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/bitcoinschema/go-b v0.0.17
github.com/bitcoinschema/go-bap v0.2.8
github.com/bitcoinschema/go-bitcoin/v2 v2.0.3
github.com/bitcoinschema/go-bob v0.3.3
github.com/bitcoinschema/go-bob v0.3.4
github.com/bitcoinschema/go-boost v0.0.1
github.com/bitcoinschema/go-bpu v0.0.5
github.com/bitcoinschema/go-bpu v0.0.6
github.com/bitcoinschema/go-map v0.0.16
github.com/libsv/go-bt/v2 v2.1.1
)
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ github.com/bitcoinschema/go-bitcoin/v2 v2.0.3 h1:3pxGpFk7L2GcAx6VYW6kgcOmI0jhnZ/
github.com/bitcoinschema/go-bitcoin/v2 v2.0.3/go.mod h1:MnikSx/hRXOS7dG3RlJOP2cV2lG6IOmoGd6HhvCB7Gc=
github.com/bitcoinschema/go-bob v0.3.1/go.mod h1:76l1qp651EjzxO8EhJSb+i6UcTDQ7hSzS/alV35XN8s=
github.com/bitcoinschema/go-bob v0.3.2/go.mod h1:ENT+iU50YGrJ8Swi/Wi7/XlBrqUYamM/Ldx3YLYQQ0E=
github.com/bitcoinschema/go-bob v0.3.3 h1:2DBWMT5LrxzD/k876gTgchTY0z3npSRes5CG+Chdrzw=
github.com/bitcoinschema/go-bob v0.3.3/go.mod h1:u381SnwMDRJqbUIZxredI9sdl6J4WYMRteDWqTcqzQQ=
github.com/bitcoinschema/go-bob v0.3.4 h1:cZu55xfKaYwh18nWObXROBnQWaY5bWXGTUnT7yPspWo=
github.com/bitcoinschema/go-bob v0.3.4/go.mod h1:/wrchZo1fbo1Hxsknue2+ihq8nF8B3EaxSdbrGx+Ft0=
github.com/bitcoinschema/go-boost v0.0.1 h1:yDBIUEjDc51HPPdag4WgAnHvFFEZUsBOGfOGdBlrGkc=
github.com/bitcoinschema/go-boost v0.0.1/go.mod h1:Z+15n8CgM1VV1Cx8CQOAo/RFUn0lXqk5OzrmtI2gyI0=
github.com/bitcoinschema/go-bpu v0.0.3/go.mod h1:i41D9NP5KIk/oCt8XrRhN27YerZCUG6vjScXDhNn5Us=
github.com/bitcoinschema/go-bpu v0.0.4/go.mod h1:i41D9NP5KIk/oCt8XrRhN27YerZCUG6vjScXDhNn5Us=
github.com/bitcoinschema/go-bpu v0.0.5 h1:+RZa6WL/K0F7s1cKcBV5WumZcGG2uQ+SlhZjoSu403A=
github.com/bitcoinschema/go-bpu v0.0.5/go.mod h1:i41D9NP5KIk/oCt8XrRhN27YerZCUG6vjScXDhNn5Us=
github.com/bitcoinschema/go-bpu v0.0.6 h1:DQ2SwZMOMaSf4mRbM6DxOezZ7aJoiyR7KLKcsE5qpmU=
github.com/bitcoinschema/go-bpu v0.0.6/go.mod h1:i41D9NP5KIk/oCt8XrRhN27YerZCUG6vjScXDhNn5Us=
github.com/bitcoinschema/go-map v0.0.16 h1:sc94gO52+M5Gb/f4RWxexqTa1riRg6ST3NzYUMynXTs=
github.com/bitcoinschema/go-map v0.0.16/go.mod h1:UATfKAVX5ILxhzCg0xOg9liqzGcY5Sz6XrH+V+CIbpY=
github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 h1:2yTIV9u7H0BhRDGXH5xrAwAz7XibWJtX2dNezMeNsUo=
Expand Down

0 comments on commit bf71f01

Please sign in to comment.