mirror of
https://github.com/aljazceru/ark.git
synced 2026-02-19 09:54:20 +01:00
* v0 unilateral redemption * add fee outputs to congestion tree * unilateral exit * rework unilateral exit verbosity * substract fee from vtxo amount * remove unused functions and variables * fix after reviews * Update noah/explorer.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * remove bufferutils --------- Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
57 lines
970 B
Go
57 lines
970 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
|
|
}
|