mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-28 09:46:50 +00:00
58 lines
2.3 KiB
Go
58 lines
2.3 KiB
Go
package rpccontext
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"github.com/fabbez/topiad/domain/consensus/utils/txscript"
|
|
"github.com/fabbez/topiad/util"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/fabbez/topiad/app/appmessage"
|
|
"github.com/fabbez/topiad/domain/utxoindex"
|
|
)
|
|
|
|
// ConvertUTXOOutpointEntryPairsToUTXOsByAddressesEntries converts
|
|
// UTXOOutpointEntryPairs to a slice of UTXOsByAddressesEntry
|
|
func ConvertUTXOOutpointEntryPairsToUTXOsByAddressesEntries(address string, pairs utxoindex.UTXOOutpointEntryPairs) []*appmessage.UTXOsByAddressesEntry {
|
|
utxosByAddressesEntries := make([]*appmessage.UTXOsByAddressesEntry, 0, len(pairs))
|
|
for outpoint, utxoEntry := range pairs {
|
|
utxosByAddressesEntries = append(utxosByAddressesEntries, &appmessage.UTXOsByAddressesEntry{
|
|
Address: address,
|
|
Outpoint: &appmessage.RPCOutpoint{
|
|
TransactionID: outpoint.TransactionID.String(),
|
|
Index: outpoint.Index,
|
|
},
|
|
UTXOEntry: &appmessage.RPCUTXOEntry{
|
|
Amount: utxoEntry.Amount(),
|
|
ScriptPublicKey: &appmessage.RPCScriptPublicKey{Script: hex.EncodeToString(utxoEntry.ScriptPublicKey().Script), Version: utxoEntry.ScriptPublicKey().Version},
|
|
BlockDAAScore: utxoEntry.BlockDAAScore(),
|
|
IsCoinbase: utxoEntry.IsCoinbase(),
|
|
},
|
|
})
|
|
}
|
|
return utxosByAddressesEntries
|
|
}
|
|
|
|
// ConvertAddressStringsToUTXOsChangedNotificationAddresses converts address strings
|
|
// to UTXOsChangedNotificationAddresses
|
|
func (ctx *Context) ConvertAddressStringsToUTXOsChangedNotificationAddresses(
|
|
addressStrings []string) ([]*UTXOsChangedNotificationAddress, error) {
|
|
|
|
addresses := make([]*UTXOsChangedNotificationAddress, len(addressStrings))
|
|
for i, addressString := range addressStrings {
|
|
address, err := util.DecodeAddress(addressString, ctx.Config.ActiveNetParams.Prefix)
|
|
if err != nil {
|
|
return nil, errors.Errorf("Could not decode address '%s': %s", addressString, err)
|
|
}
|
|
scriptPublicKey, err := txscript.PayToAddrScript(address)
|
|
if err != nil {
|
|
return nil, errors.Errorf("Could not create a scriptPublicKey for address '%s': %s", addressString, err)
|
|
}
|
|
scriptPublicKeyString := utxoindex.ScriptPublicKeyString(scriptPublicKey.String())
|
|
addresses[i] = &UTXOsChangedNotificationAddress{
|
|
Address: addressString,
|
|
ScriptPublicKeyString: scriptPublicKeyString,
|
|
}
|
|
}
|
|
return addresses, nil
|
|
}
|