Files
ark/noah/explorer.go
Louis Singer 5dba216a98 Congestion tree validation (#84)
* add common/pkg/tree validation

* update noah go.mod

* cleaning and fixes

* fix builder_test.go

* Fix deferred func

* fix even number of vtxos in congestion tree

---------

Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
2024-01-23 15:38:43 +01:00

58 lines
971 B
Go

package main
import (
"strings"
"github.com/vulpemventures/go-elements/transaction"
)
type Explorer interface {
GetTxHex(txid string) (string, error)
Broadcast(txHex string) (string, error)
}
type explorer struct {
cache map[string]string
}
func NewExplorer() Explorer {
return &explorer{
cache: make(map[string]string),
}
}
func (e *explorer) GetTxHex(txid string) (string, error) {
if hex, ok := e.cache[txid]; ok {
return hex, nil
}
txHex, err := getTxHex(txid)
if err != nil {
return "", err
}
e.cache[txid] = txHex
return txHex, nil
}
func (e *explorer) Broadcast(txHex string) (string, error) {
tx, err := transaction.NewTxFromHex(txHex)
if err != nil {
return "", err
}
txid := tx.TxHash().String()
e.cache[txid] = txHex
txid, err = broadcast(txHex)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "transaction already in block chain") {
return txid, nil
}
return "", err
}
return txid, nil
}