本文整理汇总了Golang中github.com/decred/dcrutil.Address.DSA方法的典型用法代码示例。如果您正苦于以下问题:Golang Address.DSA方法的具体用法?Golang Address.DSA怎么用?Golang Address.DSA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/decred/dcrutil.Address
的用法示例。
在下文中一共展示了Address.DSA方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PayToSSRtx
// PayToSSRtx creates a new script to pay a transaction output to a
// public key hash, but tags the output with OP_SSRTX. For use in constructing
// valid SSRtx.
func PayToSSRtx(addr dcrutil.Address) ([]byte, error) {
if addr == nil {
return nil, ErrUnsupportedAddress
}
// Only pay to pubkey hash and pay to script hash are
// supported.
scriptType := PubKeyHashTy
switch addr := addr.(type) {
case *dcrutil.AddressPubKeyHash:
if addr.DSA(addr.Net()) != chainec.ECTypeSecp256k1 {
return nil, ErrUnsupportedAddress
}
break
case *dcrutil.AddressScriptHash:
scriptType = ScriptHashTy
break
default:
return nil, ErrUnsupportedAddress
}
hash := addr.ScriptAddress()
if scriptType == PubKeyHashTy {
return NewScriptBuilder().AddOp(OP_SSRTX).AddOp(OP_DUP).
AddOp(OP_HASH160).AddData(hash).AddOp(OP_EQUALVERIFY).
AddOp(OP_CHECKSIG).Script()
}
return NewScriptBuilder().AddOp(OP_SSRTX).AddOp(OP_HASH160).
AddData(hash).AddOp(OP_EQUAL).Script()
}
示例2: GenerateSStxAddrPush
// GenerateSStxAddrPush generates an OP_RETURN push for SSGen payment addresses in
// an SStx.
func GenerateSStxAddrPush(addr dcrutil.Address, amount dcrutil.Amount,
limits uint16) ([]byte, error) {
if addr == nil {
return nil, ErrUnsupportedAddress
}
// Only pay to pubkey hash and pay to script hash are
// supported.
scriptType := PubKeyHashTy
switch addr := addr.(type) {
case *dcrutil.AddressPubKeyHash:
if addr.DSA(addr.Net()) != chainec.ECTypeSecp256k1 {
return nil, ErrUnsupportedAddress
}
break
case *dcrutil.AddressScriptHash:
scriptType = ScriptHashTy
break
default:
return nil, ErrUnsupportedAddress
}
// Prefix
dataPushes := []byte{
0x6a, // OP_RETURN
0x1e, // OP_DATA_30
}
hash := addr.ScriptAddress()
amountBuffer := make([]byte, 8)
binary.LittleEndian.PutUint64(amountBuffer, uint64(amount))
// Set the bit flag indicating pay to script hash.
if scriptType == ScriptHashTy {
amountBuffer[7] |= 1 << 7
}
limitsBuffer := make([]byte, 2)
binary.LittleEndian.PutUint16(limitsBuffer, limits)
// Concatenate the prefix, pubkeyhash, and amount.
addrOut := append(dataPushes, hash...)
addrOut = append(addrOut, amountBuffer...)
addrOut = append(addrOut, limitsBuffer...)
return addrOut, nil
}
示例3: addrToKey
// addrToKey converts known address types to an addrindex key. An error is
// returned for unsupported types.
func addrToKey(addr dcrutil.Address, params *chaincfg.Params) ([addrKeySize]byte, error) {
switch addr := addr.(type) {
case *dcrutil.AddressPubKeyHash:
switch addr.DSA(params) {
case chainec.ECTypeSecp256k1:
var result [addrKeySize]byte
result[0] = addrKeyTypePubKeyHash
copy(result[1:], addr.Hash160()[:])
return result, nil
case chainec.ECTypeEdwards:
var result [addrKeySize]byte
result[0] = addrKeyTypePubKeyHashEdwards
copy(result[1:], addr.Hash160()[:])
return result, nil
case chainec.ECTypeSecSchnorr:
var result [addrKeySize]byte
result[0] = addrKeyTypePubKeyHashSchnorr
copy(result[1:], addr.Hash160()[:])
return result, nil
}
case *dcrutil.AddressScriptHash:
var result [addrKeySize]byte
result[0] = addrKeyTypeScriptHash
copy(result[1:], addr.Hash160()[:])
return result, nil
case *dcrutil.AddressSecpPubKey:
var result [addrKeySize]byte
result[0] = addrKeyTypePubKeyHash
copy(result[1:], addr.AddressPubKeyHash().Hash160()[:])
return result, nil
case *dcrutil.AddressEdwardsPubKey:
var result [addrKeySize]byte
result[0] = addrKeyTypePubKeyHashEdwards
copy(result[1:], addr.AddressPubKeyHash().Hash160()[:])
return result, nil
case *dcrutil.AddressSecSchnorrPubKey:
var result [addrKeySize]byte
result[0] = addrKeyTypePubKeyHashSchnorr
copy(result[1:], addr.AddressPubKeyHash().Hash160()[:])
return result, nil
}
return [addrKeySize]byte{}, errUnsupportedAddressType
}
示例4: PayToAddrScript
// PayToAddrScript creates a new script to pay a transaction output to a the
// specified address.
func PayToAddrScript(addr dcrutil.Address) ([]byte, error) {
switch addr := addr.(type) {
case *dcrutil.AddressPubKeyHash:
if addr == nil {
return nil, ErrUnsupportedAddress
}
switch addr.DSA(addr.Net()) {
case chainec.ECTypeSecp256k1:
return payToPubKeyHashScript(addr.ScriptAddress())
case chainec.ECTypeEdwards:
return payToPubKeyHashEdwardsScript(addr.ScriptAddress())
case chainec.ECTypeSecSchnorr:
return payToPubKeyHashSchnorrScript(addr.ScriptAddress())
}
case *dcrutil.AddressScriptHash:
if addr == nil {
return nil, ErrUnsupportedAddress
}
return payToScriptHashScript(addr.ScriptAddress())
case *dcrutil.AddressSecpPubKey:
if addr == nil {
return nil, ErrUnsupportedAddress
}
return payToPubKeyScript(addr.ScriptAddress())
case *dcrutil.AddressEdwardsPubKey:
if addr == nil {
return nil, ErrUnsupportedAddress
}
return payToEdwardsPubKeyScript(addr.ScriptAddress())
case *dcrutil.AddressSecSchnorrPubKey:
if addr == nil {
return nil, ErrUnsupportedAddress
}
return payToSchnorrPubKeyScript(addr.ScriptAddress())
}
return nil, ErrUnsupportedAddress
}