Skip to content

Commit

Permalink
Added debug flag for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
icellan committed Jun 13, 2022
1 parent 3795bf4 commit a13bb09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
7 changes: 6 additions & 1 deletion run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"encoding/json"
"fmt"
"log"
"os"
"strconv"
"strings"

"github.com/bitcoinschema/go-bob"
"github.com/libsv/go-bt"
)

var debug = os.Getenv("BMAP_DEBUG") == "1"

// Prefix is the run protocol prefix found in the 1st pushdata
const Prefix string = "run"

Expand Down Expand Up @@ -104,7 +107,9 @@ func NewFromUtxo(utxo *bt.Output) (jig *Jig, e error) {
}
case 1:
// TODO: Convert from asm to int
log.Println("Version", val)
if debug {
log.Println("Version", val)
}
jig.Version = 0 // val
case 2:
appID, err := hex.DecodeString(val)
Expand Down
23 changes: 18 additions & 5 deletions sfp/sfp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"encoding/hex"
"fmt"
"log"
"os"
"strconv"
"strings"

"github.com/libsv/go-bt"
)

var debug = os.Getenv("BMAP_DEBUG") == "1"

// SFP - Simple Fabriik Protocol
type SFP struct {
Amount uint64
Expand Down Expand Up @@ -62,23 +65,29 @@ func NewFromUtxo(utxo *bt.Output, linkedPrevOut *string, linkedPrevOutSig *strin
}
sfp.AssetPaymail = string(assetPaymailBytes)

log.Printf("Paymail %s", sfp.AssetPaymail)
if debug {
log.Printf("Paymail %s", sfp.AssetPaymail)
}
// Set Authorizer Address
// var authorizerAddressBytes []byte
// authorizerAddressBytes, err = hex.DecodeString(scriptParts[3])
// if err != nil {
// return nil, err
// }
sfp.AuthorizerAddress = scriptParts[3]
log.Printf("Authorizer %s", sfp.AuthorizerAddress)
if debug {
log.Printf("Authorizer %s", sfp.AuthorizerAddress)
}
// Set Owner Address
// var ownerAddressBytes []byte
// ownerAddressBytes, err = hex.DecodeString(scriptParts[4])
// if err != nil {
// return nil, err
// }
sfp.OwnerAddress = scriptParts[4] // string(ownerAddressBytes)
log.Printf("Owner %s", sfp.OwnerAddress)
if debug {
log.Printf("Owner %s", sfp.OwnerAddress)
}
// Set Issuer Address
// var issuerAddressBytes []byte
// issuerAddressBytes, err = hex.DecodeString(scriptParts[5])
Expand Down Expand Up @@ -127,7 +136,9 @@ func NewFromUtxo(utxo *bt.Output, linkedPrevOut *string, linkedPrevOutSig *strin
return nil, fmt.Errorf("failed to get amount %w", err)
}
sfp.Amount = amount
log.Println("Amount", amount)
if debug {
log.Println("Amount", amount)
}

// Set notes
notes := data[0][16 : len(data[0])-6]
Expand All @@ -138,7 +149,9 @@ func NewFromUtxo(utxo *bt.Output, linkedPrevOut *string, linkedPrevOutSig *strin
return nil, fmt.Errorf("failed to get notes %w", err)
}
sfp.Notes = string(notesBytes)
log.Println("notes", sfp.Notes)
if debug {
log.Println("notes", sfp.Notes)
}

// Note on outpoints: I think format is <hex>:<out> or OP_FALSE if not present
if linkedPrevOut == nil {
Expand Down

0 comments on commit a13bb09

Please sign in to comment.