btc-pay-checker/internal/services/btc/decode_raw_transaction.go

62 lines
1.5 KiB
Go
Raw Normal View History

2023-07-19 11:47:46 +02:00
package btc
import (
"encoding/json"
)
type decodeRawTransactionResponseResult struct {
Txid string `json:"txid"`
Hash string `json:"hash"`
Version int `json:"version"`
Size int `json:"size"`
Vsize int `json:"vsize"`
Weight int `json:"weight"`
Locktime int `json:"locktime"`
Vin []struct {
Txid string `json:"txid"`
Vout int `json:"vout"`
ScriptSig struct {
Asm string `json:"asm"`
Hex string `json:"hex"`
} `json:"scriptSig"`
Txinwitness []string `json:"txinwitness"`
Sequence int64 `json:"sequence"`
} `json:"vin"`
Vout []struct {
Value float64 `json:"value"`
N int `json:"n"`
ScriptPubKey struct {
Asm string `json:"asm"`
Hex string `json:"hex"`
Address string `json:"address,omitempty"`
Type string `json:"type,omitempty"`
} `json:"scriptPubKey,omitempty"`
} `json:"vout"`
}
// func (d decodeRawTransactionResponseResult) getAddressRestFunds(amountPlusFee float64) string {
// address := ""
// for _, vout := range d.Vout {
// if vout.Value > amountPlusFee {
// address = vout.ScriptPubKey.Address
// }
// }
// return address
// }
type decodeRawTransactionResponse struct {
Result decodeRawTransactionResponseResult `json:"result"`
RPCResponse
}
func NewdecodeRawTransactionResponse(bts []byte) (*decodeRawTransactionResponse, error) {
resp := new(decodeRawTransactionResponse)
err := json.Unmarshal(bts, resp)
if err != nil {
return nil, err
}
return resp, nil
}