Example #1
0
// TransferFunds will create a transaction that transfers an amount of
// NMC-satoshis to a hashed public key.
func (a *Account) TransferFunds(amount int64, pubkeyHash string) (*Transaction, error) {
	// Decode the hex representation of the Public Key.
	hashBytes, err := hex.DecodeString(pubkeyHash)
	if err != nil {
		return nil, err
	}

	// Convert it to a btcd address object.
	addr, err := btcutil.NewAddressPubKeyHash(hashBytes, &chaincfg.MainNetParams)
	if err != nil {
		return nil, err
	}

	// Generate the pkScript for this output.
	pkScript, err := txscript.PayToAddrScript(addr)
	if err != nil {
		return nil, err
	}

	// That is the only output here.
	txOutput := []*wire.TxOut{
		wire.NewTxOut(amount, pkScript),
	}

	// Build the transaction.
	return a.buildTransaction(txOutput)
}
Example #2
0
// getPubKeyHash will return the public key hash of the current
// account.
func (a *Account) PublicKeyHash() (*btcutil.AddressPubKeyHash, error) {
	compressed := a.Keys.Key().PubKey().SerializeCompressed()

	return btcutil.NewAddressPubKeyHash(btcutil.Hash160(compressed), &chaincfg.MainNetParams)
}