本文整理汇总了Golang中github.com/piotrnar/gocoin/btc.NewAddrFromString函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAddrFromString函数的具体用法?Golang NewAddrFromString怎么用?Golang NewAddrFromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAddrFromString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parse_spend
// parse the "-send ..." parameter
func parse_spend() {
// No dump, so send money...
outs := strings.Split(*send, ",")
sendTo = make([]oneSendTo, len(outs))
for i := range outs {
tmp := strings.Split(strings.Trim(outs[i], " "), "=")
if len(tmp) != 2 {
println("The otputs must be in a format address1=amount1[,addressN=amountN]\007")
os.Exit(1)
}
a, e := btc.NewAddrFromString(tmp[0])
if e != nil {
println("NewAddrFromString:", e.Error(), "\007")
os.Exit(1)
}
sendTo[i].addr = a
am, e := strconv.ParseFloat(tmp[1], 64)
if e != nil {
println("ParseFloat:", e.Error(), "\007")
os.Exit(1)
}
sendTo[i].amount = uint64(am * 1e8)
spendBtc += sendTo[i].amount
}
feeBtc = uint64(*fee * 1e8)
}
示例2: get_change_addr
// return the change addrress or nil if there will be no change
func get_change_addr() (chng *btc.BtcAddr) {
if *change != "" {
var e error
chng, e = btc.NewAddrFromString(*change)
if e != nil {
println("Change address:", e.Error())
os.Exit(1)
}
return
}
// If change address not specified, send it back to the first input
uo := UO(unspentOuts[0])
for j := range publ_addrs {
if publ_addrs[j].Owns(uo.Pk_script) {
if is_stealth[j] {
println("Cannot send change to a stealth address. Use -change param")
os.Exit(1)
}
chng = publ_addrs[j]
return
}
}
fmt.Println("You do not own the address of the first input, nor specified -change")
os.Exit(1)
return
}
示例3: parse_spend
// parse the "-send ..." parameter
func parse_spend() {
outs := strings.Split(*send, ",")
for i := range outs {
tmp := strings.Split(strings.Trim(outs[i], " "), "=")
if len(tmp) != 2 {
println("The otputs must be in a format address1=amount1[,addressN=amountN]")
os.Exit(1)
}
a, e := btc.NewAddrFromString(tmp[0])
if e != nil {
println("NewAddrFromString:", e.Error())
os.Exit(1)
}
am, er := btc.StringToSatoshis(tmp[1])
if er != nil {
println("Incorrect amount: ", tmp[1], er.Error())
os.Exit(1)
}
if *subfee {
am -= curFee
}
sendTo = append(sendTo, oneSendTo{addr: a, amount: am})
spendBtc += am
}
}
示例4: dump_prvkey
func dump_prvkey() {
if *dumppriv == "*" {
// Dump all private keys
for i := range priv_keys {
if len(publ_addrs[i].Pubkey) == 33 {
fmt.Println(sec2b58com(priv_keys[i]), publ_addrs[i].String(), labels[i])
} else {
fmt.Println(sec2b58unc(priv_keys[i]), publ_addrs[i].String(), labels[i])
}
}
} else {
// single key
a, e := btc.NewAddrFromString(*dumppriv)
if e != nil {
println("Dump Private Key:", e.Error())
return
}
if a.Version != verbyte {
println("Dump Private Key: Version byte mismatch", a.Version, verbyte)
return
}
for i := range priv_keys {
if publ_addrs[i].Hash160 == a.Hash160 {
if len(publ_addrs[i].Pubkey) == 33 {
fmt.Println(sec2b58com(priv_keys[i]), publ_addrs[i].String(), labels[i])
} else {
fmt.Println(sec2b58unc(priv_keys[i]), publ_addrs[i].String(), labels[i])
}
return
}
}
println("Dump Private Key:", a.String(), "not found it the wallet")
}
}
示例5: LoadWalfile
func LoadWalfile(fn string, included int) (addrs []*btc.BtcAddr) {
waldir, walname := filepath.Split(fn)
if walname[0] == '.' {
walname = walname[1:] // remove trailing dot (from hidden wallets)
}
f, e := os.Open(fn)
if e != nil {
println(e.Error())
return
}
defer f.Close()
rd := bufio.NewReader(f)
linenr := 0
for {
var l string
l, e = rd.ReadString('\n')
space_first := len(l) > 0 && l[0] == ' '
l = strings.Trim(l, " \t\r\n")
linenr++
//println(fmt.Sprint(fn, ":", linenr), "...")
if len(l) > 0 {
if l[0] == '@' {
if included > 3 {
println(fmt.Sprint(fn, ":", linenr), "Too many nested wallets")
} else {
ifn := strings.Trim(l[1:], " \n\t\t")
addrs = append(addrs, LoadWalfile(waldir+ifn, included+1)...)
}
} else {
var s string
if l[0] != '#' {
s = l
} else if !PrecachingComplete && len(l) > 10 && l[1] == '1' {
s = l[1:] // While pre-caching addresses, include ones that are commented out
}
if s != "" {
ls := strings.SplitN(s, " ", 2)
if len(ls) > 0 {
a, e := btc.NewAddrFromString(ls[0])
if e != nil {
println(fmt.Sprint(fn, ":", linenr), e.Error())
} else {
a.Extra.Wallet = walname
if len(ls) > 1 {
a.Extra.Label = ls[1]
}
a.Extra.Virgin = space_first
addrs = append(addrs, a)
}
}
}
}
}
if e != nil {
break
}
}
return
}
示例6: main
func main() {
if len(os.Args) < 3 {
fmt.Println("Specify at least two parameters:")
fmt.Println(" 1) The base58 encoded bitcoin addres, that the signature was made with")
fmt.Println(" 2) The base64 encoded signature for the message...")
fmt.Println("If you specify a 3rd parameter - this will be assumed to be the message you want to verify")
fmt.Println("If you do not specify a 3rd parameter - the message will be read from stdin")
return
}
ad, er := btc.NewAddrFromString(os.Args[1])
if er != nil {
println("Address:", er.Error())
return
}
nv, btcsig, er := btc.ParseMessageSignature(os.Args[2])
if er != nil {
println("ParseMessageSignature:", er.Error())
return
}
var msg []byte
if len(os.Args) < 4 {
msg, _ = ioutil.ReadAll(os.Stdin)
} else {
msg = []byte(os.Args[3])
}
hash := make([]byte, 32)
btc.HashFromMessage(msg, hash)
compressed := false
if nv >= 31 {
//println("compressed key")
nv -= 4
compressed = true
}
pub := btcsig.RecoverPublicKey(hash[:], int(nv-27))
if pub != nil {
pk := pub.Bytes(compressed)
ok := btc.EcdsaVerify(pk, btcsig.Bytes(), hash)
if ok {
sa := btc.NewAddrFromPubkey(pk, ad.Version)
if ad.Hash160 != sa.Hash160 {
fmt.Println("BAD signature for", ad.String())
os.Exit(1)
} else {
fmt.Println("Good signature for", sa.String())
}
} else {
println("BAD signature")
os.Exit(1)
}
} else {
println("BAD, BAD, BAD signature")
os.Exit(1)
}
}
示例7: list_unspent
func list_unspent(addr string) {
fmt.Println("Checking unspent coins for addr", addr)
var a [1]*btc.BtcAddr
var e error
a[0], e = btc.NewAddrFromString(addr)
if e != nil {
println(e.Error())
return
}
unsp := BlockChain.GetAllUnspent(a[:], false)
var sum uint64
for i := range unsp {
fmt.Println(unsp[i].String())
sum += unsp[i].Value
}
fmt.Printf("Total %.8f unspent BTC at address %s\n", float64(sum)/1e8, a[0].String())
}
示例8: LoadWalfile
func LoadWalfile(fn string, included bool) (addrs []*btc.BtcAddr) {
waldir, walname := filepath.Split(fn)
f, e := os.Open(fn)
if e != nil {
println(e.Error())
return
}
defer f.Close()
rd := bufio.NewReader(f)
linenr := 0
for {
var l string
l, e = rd.ReadString('\n')
l = strings.Trim(l, " \t\r\n")
linenr++
//println(fmt.Sprint(fn, ":", linenr), "...")
if len(l) > 0 {
if l[0] == '@' {
if included {
println(fmt.Sprint(fn, ":", linenr), "You cannot include wallets recursively")
} else {
ifn := strings.Trim(l[1:], " \n\t\t")
addrs = append(addrs, LoadWalfile(waldir+ifn, true)...)
}
} else if l[0] != '#' {
ls := strings.SplitN(l, " ", 2)
if len(ls) > 0 {
a, e := btc.NewAddrFromString(ls[0])
if e != nil {
println(fmt.Sprint(fn, ":", linenr), e.Error())
} else {
if len(ls) > 1 {
a.Label = strings.Trim(ls[1], " \n\t\t")
}
a.Label += "@" + walname
addrs = append(addrs, a)
}
}
}
}
if e != nil {
break
}
}
return
}
示例9: parse_batch
func parse_batch() {
f, e := os.Open(*batch)
if e == nil {
defer f.Close()
td := bufio.NewReader(f)
var lcnt int
for {
li, _, _ := td.ReadLine()
if li == nil {
break
}
lcnt++
tmp := strings.SplitN(strings.Trim(string(li), " "), "=", 2)
if len(tmp) < 2 {
println("Error in the batch file line", lcnt)
os.Exit(1)
}
if tmp[0][0] == '#' {
continue // Just a comment-line
}
a, e := btc.NewAddrFromString(tmp[0])
if e != nil {
println("NewAddrFromString:", e.Error())
os.Exit(1)
}
am, e := btc.StringToSatoshis(tmp[1])
if e != nil {
println("StringToSatoshis:", e.Error())
os.Exit(1)
}
sendTo = append(sendTo, oneSendTo{addr: a, amount: am})
spendBtc += am
}
} else {
println(e.Error())
os.Exit(1)
}
}
示例10: parse_spend
// parse the "-send ..." parameter
func parse_spend() {
outs := strings.Split(*send, ",")
for i := range outs {
tmp := strings.Split(strings.Trim(outs[i], " "), "=")
if len(tmp) != 2 {
println("The otputs must be in a format address1=amount1[,addressN=amountN]")
os.Exit(1)
}
a, e := btc.NewAddrFromString(tmp[0])
if e != nil {
println("NewAddrFromString:", e.Error())
os.Exit(1)
}
am := btc.ParseValue(tmp[1])
sendTo = append(sendTo, oneSendTo{addr: a, amount: am})
spendBtc += am
}
}
示例11: get_change_addr
// return the change addrress or nil if there will be no change
func get_change_addr() (chng *btc.BtcAddr) {
if *change != "" {
var e error
chng, e = btc.NewAddrFromString(*change)
if e != nil {
println("Change address:", e.Error(), "\007")
os.Exit(1)
}
}
// If change address not specified, send it back to the first input
uo := UO(unspentOuts[0])
for j := range publ_addrs {
if publ_addrs[j].Owns(uo.Pk_script) {
chng = publ_addrs[j]
return
}
}
fmt.Println("You do not own the address of the first input\007")
os.Exit(1)
return
}
示例12: NewWallet
// Load public wallet from a text file
func NewWallet(fn string) (wal *OneWallet) {
f, e := os.Open(fn)
if e != nil {
println(e.Error())
return
}
defer f.Close()
wal = new(OneWallet)
wal.FileName = fn
rd := bufio.NewReader(f)
for {
var l string
l, e = rd.ReadString('\n')
l = strings.Trim(l, " \t\r\n")
if len(l) > 0 && l[0] != '#' {
ls := strings.SplitN(l, " ", 2)
if len(ls) > 0 {
a, e := btc.NewAddrFromString(ls[0])
if e != nil {
println(l, ": ", e.Error())
} else {
if len(ls) > 1 {
a.Label = strings.Trim(ls[1], " \n\t\t")
}
wal.Addrs = append(wal.Addrs, a)
}
}
}
if e != nil {
break
}
}
if len(wal.Addrs) == 0 {
wal = nil
}
return
}
示例13: NewWallet
func NewWallet(fn string) (wal *oneWallet) {
f, e := os.Open(fn)
if e != nil {
println(e.Error())
return
}
defer f.Close()
wal = new(oneWallet)
rd := bufio.NewReader(f)
for {
var l string
l, e = rd.ReadString('\n')
l = strings.Trim(l, " \t\r\n")
if len(l) > 0 && l[0] != '#' {
ls := strings.SplitN(l, " ", 2)
if len(ls) > 0 {
a, e := btc.NewAddrFromString(ls[0])
if e != nil {
println(l, ": ", e.Error())
} else {
wal.addrs = append(wal.addrs, a)
if len(ls) > 1 {
wal.label = append(wal.label, strings.Trim(ls[1], " \n\t\t"))
} else {
wal.label = append(wal.label, "")
}
}
}
}
if e != nil {
break
}
}
println(len(wal.addrs), "addresses loaded from", fn)
return
}
示例14: dl_payment
func dl_payment(w http.ResponseWriter, r *http.Request) {
if !ipchecker(r) {
return
}
var err string
r.ParseForm()
if len(r.Form["outcnt"]) == 1 {
var thisbal btc.AllUnspentTx
var pay_cmd string
var totalinput, spentsofar uint64
var change_addr *btc.BtcAddr
tx := new(btc.Tx)
tx.Version = 1
tx.Lock_time = 0
outcnt, _ := strconv.ParseUint(r.Form["outcnt"][0], 10, 32)
wallet.LockBal()
for i := 1; i <= int(outcnt); i++ {
is := fmt.Sprint(i)
if len(r.Form["txout"+is]) == 1 && r.Form["txout"+is][0] == "on" {
hash := btc.NewUint256FromString(r.Form["txid"+is][0])
if hash != nil {
vout, er := strconv.ParseUint(r.Form["txvout"+is][0], 10, 32)
if er == nil {
var po = btc.TxPrevOut{Hash: hash.Hash, Vout: uint32(vout)}
for j := range wallet.MyBalance {
if wallet.MyBalance[j].TxPrevOut == po {
thisbal = append(thisbal, wallet.MyBalance[j])
// Add the input to our tx
tin := new(btc.TxIn)
tin.Input = wallet.MyBalance[j].TxPrevOut
tin.Sequence = 0xffffffff
tx.TxIn = append(tx.TxIn, tin)
totalinput += wallet.MyBalance[j].Value
if change_addr == nil {
change_addr = wallet.MyBalance[j].BtcAddr
}
}
}
}
}
}
}
wallet.UnlockBal()
for i := 1; ; i++ {
adridx := fmt.Sprint("adr", i)
btcidx := fmt.Sprint("btc", i)
if len(r.Form[adridx]) != 1 || len(r.Form[btcidx]) != 1 {
break
}
if len(r.Form[adridx][0]) > 1 {
addr, er := btc.NewAddrFromString(r.Form[adridx][0])
if er == nil {
am, er := btc.StringToSatoshis(r.Form[btcidx][0])
if er == nil && am > 0 {
if pay_cmd == "" {
pay_cmd = "wallet -useallinputs -send "
} else {
pay_cmd += ","
}
pay_cmd += addr.Enc58str + "=" + btc.UintToBtc(am)
tout := new(btc.TxOut)
tout.Value = am
tout.Pk_script = addr.OutScript()
tx.TxOut = append(tx.TxOut, tout)
spentsofar += am
} else {
err = "Incorrect amount (" + r.Form[btcidx][0] + ") for Output #" + fmt.Sprint(i)
goto error
}
} else {
err = "Incorrect address (" + r.Form[adridx][0] + ") for Output #" + fmt.Sprint(i)
goto error
}
}
}
if pay_cmd == "" {
err = "No inputs selected"
goto error
}
am, er := btc.StringToSatoshis(r.Form["txfee"][0])
if er != nil {
err = "Incorrect fee value: " + r.Form["txfee"][0]
goto error
}
//.........这里部分代码省略.........
示例15: sign_message
func sign_message() {
ad2s, e := btc.NewAddrFromString(*signaddr)
if e != nil {
println(e.Error())
return
}
var privkey *ecdsa.PrivateKey
for i := range publ_addrs {
if publ_addrs[i].Hash160 == ad2s.Hash160 {
privkey = new(ecdsa.PrivateKey)
pub, e := btc.NewPublicKey(publ_addrs[i].Pubkey)
if e != nil {
println(e.Error())
return
}
privkey.PublicKey = pub.PublicKey
privkey.D = new(big.Int).SetBytes(priv_keys[i][:])
break
}
}
if privkey == nil {
println("You do not have a private key for", ad2s.String())
return
}
var msg []byte
if *message == "" {
msg, _ = ioutil.ReadAll(os.Stdin)
} else {
msg = []byte(*message)
}
hash := make([]byte, 32)
btc.HashFromMessage(msg, hash)
btcsig := new(btc.Signature)
var sb [65]byte
sb[0] = 27
if !*uncompressed {
sb[0] += 4
}
btcsig.R, btcsig.S, e = ecdsa_Sign(privkey, hash)
if e != nil {
println(e.Error())
return
}
rd := btcsig.R.Bytes()
sd := btcsig.S.Bytes()
copy(sb[1+32-len(rd):], rd)
copy(sb[1+64-len(sd):], sd)
rpk := btcsig.RecoverPublicKey(hash[:], 0)
sa := btc.NewAddrFromPubkey(rpk.Bytes(!*uncompressed), ad2s.Version)
if sa.Hash160 == ad2s.Hash160 {
fmt.Println(base64.StdEncoding.EncodeToString(sb[:]))
return
}
rpk = btcsig.RecoverPublicKey(hash[:], 1)
sa = btc.NewAddrFromPubkey(rpk.Bytes(!*uncompressed), ad2s.Version)
if sa.Hash160 == ad2s.Hash160 {
sb[0]++
fmt.Println(base64.StdEncoding.EncodeToString(sb[:]))
return
}
println("Something went wrong. The message has not been signed.")
}