2017-09-09 22:54:58 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "bytes"
|
|
|
|
|
|
|
|
// TXOutput represents a transaction output
|
|
|
|
type TXOutput struct {
|
|
|
|
Value int
|
|
|
|
ScriptPubKey []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock signs the output
|
|
|
|
func (out *TXOutput) Lock(address []byte) {
|
|
|
|
pubKeyHash := Base58Decode(address)
|
|
|
|
pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
|
|
|
|
out.ScriptPubKey = pubKeyHash
|
|
|
|
}
|
|
|
|
|
2017-09-10 00:45:15 -05:00
|
|
|
// IsLockedWithKey checks if the output can be used by the owner of the pubkey
|
|
|
|
func (out *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool {
|
2017-09-09 22:54:58 -05:00
|
|
|
return bytes.Compare(out.ScriptPubKey, pubKeyHash) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTXOutput create a new TXOutput
|
|
|
|
func NewTXOutput(value int, address string) *TXOutput {
|
|
|
|
txo := &TXOutput{value, nil}
|
|
|
|
txo.Lock([]byte(address))
|
|
|
|
|
|
|
|
return txo
|
|
|
|
}
|