Exemplo n.º 1
0
// GobDecode will decode the key using the PrivKeyFromBytes function.
func (k *Key) GobDecode(b []byte) error {
	key, _ := btcec.PrivKeyFromBytes(btcec.S256(), b)
	if key == nil {
		return errors.New("zooko: couldn't unmarshal key")
	}

	*k = Key(*key)
	return nil
}
Exemplo n.º 2
0
// CreateAccount will generate a new Namecoin address and associated
// account.
func CreateAccount() (*Account, error) {
	key, err := btcec.NewPrivateKey(btcec.S256())
	if err != nil {
		return nil, err
	}
	accountKey := Key(*key)

	return &Account{
		Keys:   &accountKey,
		NameTx: make(map[string]UTXOList),
	}, nil
}
Exemplo n.º 3
0
func main() {
	pkScriptData, err := hex.DecodeString(pkScriptHex)
	if err != nil {
		log.Fatal(err)
	}

	data, err := hex.DecodeString(privateKey)
	if err != nil {
		log.Fatal(err)
	}

	key, _ := btcec.PrivKeyFromBytes(btcec.S256(), data)
	if err != nil {
		log.Fatal(err)
	}

	utxo.PkScript = pkScriptData

	acc := &account.Account{
		Keys:    key,
		Unspent: account.UTXOList([]*account.UTXO{&utxo}),
	}

	// tx, rand, err := acc.CreateNameNew("test/melange")
	// if err != nil {
	// 	log.Fatal(err)
	// }

	rand, err := hex.DecodeString("e4de61166713cf9e")
	if err != nil {
		log.Fatal(err)
	}

	tx, err := acc.CreateNameFirstUpdate(rand, "test/melange", "Hello from Golang!")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Here is your raw transaction:")

	buf := new(bytes.Buffer)
	err = tx.MsgTx.Serialize(buf)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(hex.EncodeToString(buf.Bytes()))

	// fmt.Println("Here is the random data:")
	// fmt.Println(hex.EncodeToString(rand))
}
Exemplo n.º 4
0
func main() {
	pkScriptData, err := hex.DecodeString(pkScriptHex)
	if err != nil {
		log.Fatal(err)
	}

	data, err := hex.DecodeString(privateKey)
	if err != nil {
		log.Fatal(err)
	}

	key, _ := btcec.PrivKeyFromBytes(btcec.S256(), data)
	if err != nil {
		log.Fatal(err)
	}

	utxo.PkScript = pkScriptData

	acc := &account.Account{
		Keys:    key,
		Unspent: account.UTXOList([]*account.UTXO{&utxo}),
	}

	addr, err := btcutil.DecodeAddress(toAddress, &chaincfg.MainNetParams)
	if err != nil {
		fmt.Println("Addr error")
		log.Fatal(err)
	}

	// pkHashAddr := addr.(*btcutil.AddressPubKeyHash)
	// pkHashAddr.ScriptAddre

	pkHash := hex.EncodeToString(addr.ScriptAddress())

	tx, err := acc.TransferFunds(5e5, pkHash)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Here is your raw transaction:")

	buf := new(bytes.Buffer)
	err = tx.MsgTx.Serialize(buf)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(hex.EncodeToString(buf.Bytes()))
}