doge

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionAuxPoW = 256
	CoinbaseVOut  = 0xffffffff
)
View Source
const (
	ECPrivKeyLen            = 32 // bytes.
	ECPubKeyCompressedLen   = 33 // bytes: [x02/x03][32-X] 2=even 3=odd
	ECPubKeyUncompressedLen = 65 // bytes: [x04][32-X][32-Y]
)
View Source
const (
	OP_0     = 0x00 // push empty array
	OP_FALSE = 0x00 // alias
	// 0x01..0x4b push data of `opcode` length (1-75)
	OP_PUSHDATA1           = 0x4c // 1-byte length, push data
	OP_PUSHDATA2           = 0x4d // 2-byte length, push data
	OP_PUSHDATA4           = 0x4e // 4-byte length, push data
	OP_1NEGATE             = 0x4f // push #-1
	OP_RESERVED            = 0x50
	OP_1                   = 0x51 // push #1
	OP_TRUE                = 0x51 // alias
	OP_2                   = 0x52
	OP_3                   = 0x53
	OP_4                   = 0x54
	OP_5                   = 0x55
	OP_6                   = 0x56
	OP_7                   = 0x57
	OP_8                   = 0x58
	OP_9                   = 0x59
	OP_10                  = 0x5a
	OP_11                  = 0x5b
	OP_12                  = 0x5c
	OP_13                  = 0x5d
	OP_14                  = 0x5e
	OP_15                  = 0x5f
	OP_16                  = 0x60
	OP_NOP                 = 0x61
	OP_VER                 = 0x62
	OP_IF                  = 0x63
	OF_NOTIF               = 0x64
	OP_VERIF               = 0x65
	OP_VERNOTIF            = 0x66
	OP_ELSE                = 0x67
	OP_ENDIF               = 0x68
	OP_VERIFY              = 0x69
	OP_RETURN              = 0x6a
	OP_TOALTSTACK          = 0x6b
	OP_FROMALTSTACK        = 0x6c
	OP_IFDUP               = 0x73
	OP_DEPTH               = 0x74
	OP_DROP                = 0x75
	OP_DUP                 = 0x76
	OP_NIP                 = 0x77
	OP_OVER                = 0x78
	OP_PICK                = 0x79
	OP_ROLL                = 0x7a
	OP_ROT                 = 0x7b
	OP_SWAP                = 0x7c
	OP_TUCK                = 0x7d
	OP_2DROP               = 0x6d
	OP_2DUP                = 0x6e
	OP_3DUP                = 0x6f
	OP_2OVER               = 0x70
	OP_2ROT                = 0x71
	OP_2SWAP               = 0x72
	OP_CAT                 = 0x7e
	OP_SUBSTR              = 0x7
	OP_LEFT                = 0x80
	OP_RIGHT               = 0x81
	OP_SIZE                = 0x82
	OP_INVERT              = 0x83
	OP_AND                 = 0x84
	OP_OR                  = 0x85
	OP_XOR                 = 0x86
	OP_EQUAL               = 0x87
	OP_EQUALVERIFY         = 0x88
	OP_RESERVED1           = 0x89
	OP_RESERVED2           = 0x8a
	OP_1ADD                = 0x8b
	OP_1SUB                = 0x8c
	OP_2MUL                = 0x8d
	OP_2DIV                = 0x8e
	OP_NEGATE              = 0x8f
	OP_ABS                 = 0x90
	OP_NOT                 = 0x91
	OP_0NOTEQUAL           = 0x92
	OP_ADD                 = 0x93
	OP_SUB                 = 0x94
	OP_MUL                 = 0x95
	OP_DIV                 = 0x96
	OP_MOD                 = 0x97
	OP_LSHIFT              = 0x98
	OP_RSHIFT              = 0x99
	OP_BOOLAND             = 0x9a
	OP_BOOLOR              = 0x9b
	OP_NUMEQUAL            = 0x9c
	OP_NUMEQUALVERIFY      = 0x9d
	OP_NUMNOTEQUAL         = 0x9e
	OP_LESSTHAN            = 0x9f
	OP_GREATERTHAN         = 0xa0
	OP_LESSTHANOREQUAL     = 0xa1
	OP_GREATERTHANOREQUAL  = 0xa2
	OP_MIN                 = 0xa3
	OP_MAX                 = 0xa4
	OP_WITHIN              = 0xa5
	OP_RIPEMD160           = 0xa6
	OP_SHA1                = 0xa7
	OP_SHA256              = 0xa8
	OP_HASH160             = 0xa9
	OP_HASH256             = 0xaa
	OP_CODESEPARATOR       = 0xab
	OP_CHECKSIG            = 0xac
	OP_CHECKSIGVERIFY      = 0xad
	OP_CHECKMULTISIG       = 0xae
	OP_CHECKMULTISIGVERIFY = 0xaf
	OP_NOP1                = 0xb0
	OP_CHECKLOCKTIMEVERIFY = 0xb1
	OP_CHECKSEQUENCEVERIFY = 0xb2
	OP_NOP4                = 0xb3
	OP_NOP5                = 0xb4
	OP_NOP6                = 0xb5
	OP_NOP7                = 0xb6
	OP_NOP8                = 0xb7
	OP_NOP9                = 0xb8
	OP_NOP10               = 0xb9
	OP_CHECKSIGADD         = 0xba
)

source: https://en.bitcoin.it/wiki/Script

View Source
const (
	OneDoge = int64(100_000_000) // in Koinu
)
View Source
const (
	SerializedBip32KeyLength = 4 + 1 + 4 + 4 + 32 + 33
)

Variables

View Source
var CoinbaseTxID = [32]byte{}

Functions

func Base58Decode

func Base58Decode(str string) ([]byte, error)

func Base58DecodeCheck

func Base58DecodeCheck(str string) ([]byte, error)

func Base58Encode

func Base58Encode(bytes []byte) string

func Base58EncodeCheck

func Base58EncodeCheck(bytes []byte) string

CAUTION: appends the Checksum to `bytes` if it has sufficient capacity (4 bytes)

func Base58VerifyChecksum

func Base58VerifyChecksum(bytes []byte, str string) error

func ClassifyScript

func ClassifyScript(script []byte, chain *ChainParams) (ScriptType, Address)

func DecodeECPrivKeyWIF

func DecodeECPrivKeyWIF(str string, chain *ChainParams) (ec_priv_key ECPrivKey, out_chain *ChainParams, err error)

chain is optional, will auto-detect if nil.

func ECKeyIsValid

func ECKeyIsValid(pk ECPrivKey) bool

func EncodeBip32WIF

func EncodeBip32WIF(key *Bip32Key) (string, error)

func EncodeECPrivKeyUncompressedWIF

func EncodeECPrivKeyUncompressedWIF(key ECPrivKey, chain *ChainParams) string

func EncodeECPrivKeyWIF

func EncodeECPrivKeyWIF(key ECPrivKey, chain *ChainParams) string

func ExtractECPrivKeyFromBip32

func ExtractECPrivKeyFromBip32(ext_key_wif string) (ec_privkey_wif string, err error)

Given a Bip32 Extended Private Key WIF, extract the WIF-encoded EC Private Key.

func Hash160

func Hash160(bytes []byte) []byte

func HexDecode

func HexDecode(str string) ([]byte, error)

func HexEncode

func HexEncode(bytes []byte) string

func HexEncodeReversed

func HexEncodeReversed(data []byte) string

func IsValidHex

func IsValidHex(hex string) bool

func KoinuToDecimal

func KoinuToDecimal(koinu int64) decimal.Decimal

func RIPEMD160

func RIPEMD160(bytes []byte) []byte

func TxHashHex

func TxHashHex(tx []byte) string

func ValidateP2PKH

func ValidateP2PKH(address Address, chain *ChainParams) bool

func ValidateP2SH

func ValidateP2SH(address Address, chain *ChainParams) bool

Types

type Address

type Address string // Dogecoin address (base-58 Public Key Hash aka PKH)

func GenerateP2PKHFromECPrivKeyWIF

func GenerateP2PKHFromECPrivKeyWIF(ec_priv_key_wif string) (p2pkh Address, err error)

func Hash160toAddress

func Hash160toAddress(hash []byte, prefix byte) Address

func PubKeyToP2PKH

func PubKeyToP2PKH(key []byte, chain *ChainParams) (Address, error)

func ScriptToP2SH

func ScriptToP2SH(redeemScript []byte, chain *ChainParams) Address

type Bip32Key

type Bip32Key struct {
	// contains filtered or unexported fields
}

https://en.bitcoin.it/wiki/BIP_0032

func DecodeBip32WIF

func DecodeBip32WIF(extendedKey string, chain *ChainParams) (*Bip32Key, error)

chain is optional, will auto-detect if nil.

func (*Bip32Key) Clear

func (key *Bip32Key) Clear()

func (*Bip32Key) GetECPrivKey

func (key *Bip32Key) GetECPrivKey() ([]byte, error)

func (*Bip32Key) GetECPubKey

func (key *Bip32Key) GetECPubKey() []byte

type Block

type Block struct {
	Header BlockHeader
	AuxPoW *MerkleTx // if IsAuxPoW()
	Tx     []BlockTx
}

func DecodeBlock

func DecodeBlock(blockBytes []byte) Block

type BlockHeader

type BlockHeader struct {
	Version    uint32
	PrevBlock  []byte // 32 bytes
	MerkleRoot []byte // 32 bytes
	Timestamp  uint32
	Bits       uint32
	Nonce      uint32
}

func (*BlockHeader) IsAuxPoW

func (b *BlockHeader) IsAuxPoW() bool

type BlockTx

type BlockTx struct {
	Version  uint32
	VIn      []BlockTxIn
	VOut     []BlockTxOut
	LockTime uint32
	TxID     string // hex, computed from tx data
}

func DecodeTx

func DecodeTx(txBytes []byte) BlockTx

type BlockTxIn

type BlockTxIn struct {
	TxID     []byte // 32 bytes
	VOut     uint32
	Script   []byte // varied length
	Sequence uint32
}

type BlockTxOut

type BlockTxOut struct {
	Value  int64
	Script []byte // varied length
}

type ChainParams

type ChainParams struct {
	ChainName    string
	GenesisBlock string

	Bip32_WIF_PrivKey_Prefix string
	Bip32_WIF_PubKey_Prefix  string
	// contains filtered or unexported fields
}
var BitcoinMainChain ChainParams = ChainParams{
	ChainName:    "btc_main",
	GenesisBlock: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",

	Bip32_WIF_PrivKey_Prefix: "xxxx",
	Bip32_WIF_PubKey_Prefix:  "xxxx",
	// contains filtered or unexported fields
}

Used in tests only.

var DogeMainNetChain ChainParams = ChainParams{
	ChainName:    "doge_main",
	GenesisBlock: "1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691",

	Bip32_WIF_PrivKey_Prefix: "dgpv",
	Bip32_WIF_PubKey_Prefix:  "dgub",
	// contains filtered or unexported fields
}
var DogeRegTestChain ChainParams = ChainParams{
	ChainName:    "doge_regtest",
	GenesisBlock: "3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5",

	Bip32_WIF_PrivKey_Prefix: "tprv",
	Bip32_WIF_PubKey_Prefix:  "tpub",
	// contains filtered or unexported fields
}
var DogeTestNetChain ChainParams = ChainParams{
	ChainName:    "doge_test",
	GenesisBlock: "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e",

	Bip32_WIF_PrivKey_Prefix: "tprv",
	Bip32_WIF_PubKey_Prefix:  "tpub",
	// contains filtered or unexported fields
}

func ChainFromBip32Version

func ChainFromBip32Version(version uint32, allowNonDoge bool) *ChainParams

func ChainFromGenesisHash

func ChainFromGenesisHash(hash string) (*ChainParams, error)

func ChainFromKeyBits

func ChainFromKeyBits(keyType KeyBits) *ChainParams

func ChainFromTestNetFlag

func ChainFromTestNetFlag(isTestNet bool) *ChainParams

func ChainFromWIFPrefix

func ChainFromWIFPrefix(bytes []byte, allowNonDoge bool) *ChainParams

CAUTION: the result is a best-guess based on the 'version byte' in the decoded WIF data. Do not rely on the returned ChainParams alone for validation: it will fall back on DogeTestNetChain for unknown version bytes (so verify the version byte or bip32-prefix as well)

func ChainFromWIFString

func ChainFromWIFString(wif string) *ChainParams

CAUTION: the result is a best-guess based on the 'version byte' in the WIF string. Do not rely on the returned ChainParams alone for validation: it will fall back on DogeTestNetChain for unknown version bytes (so verify the version byte or bip32-prefix as well)

type ECPrivKey

type ECPrivKey = []byte // 32 bytes.

func GenerateECPrivKey

func GenerateECPrivKey() (ECPrivKey, error)

type ECPubKeyCompressed

type ECPubKeyCompressed = []byte // 33 bytes with 0x02 or 0x03 prefix.

func ECPubKeyFromECPrivKey

func ECPubKeyFromECPrivKey(pk ECPrivKey) ECPubKeyCompressed

type ECPubKeyUncompressed

type ECPubKeyUncompressed = []byte // 65 bytes with 0x04 prefix.

type Hash256

type Hash256 = []byte

func DoubleSha256

func DoubleSha256(bytes []byte) Hash256

func Sha256

func Sha256(bytes []byte) Hash256

type KeyBits

type KeyBits = int // keyECPriv,keyECPub,keyBip32Priv,keyBip32Pub,dogeMainNet,dogeTestNet

func KeyBitsForChain

func KeyBitsForChain(chain *ChainParams) KeyBits

type MerkleBranch

type MerkleBranch struct {
	Hash     [][]byte // 32 bytes each
	SideMask uint32
}

type MerkleTx

type MerkleTx struct {
	CoinbaseTx       BlockTx
	ParentHash       []byte // 32 bytes
	CoinbaseBranch   MerkleBranch
	BlockchainBranch MerkleBranch
	ParentBlock      BlockHeader
}

type ScriptType

type ScriptType string

Dogecoin Script Types enum. Inferred from ScriptPubKey scripts by pattern-matching the code (script templates)

const (
	ScriptTypeP2PK     ScriptType = "p2pk"     // TX_PUBKEY (in Core)
	ScriptTypeP2PKH    ScriptType = "p2pkh"    // TX_PUBKEYHASH
	ScriptTypeP2PKHW   ScriptType = "p2wpkh"   // TX_WITNESS_V0_KEYHASH
	ScriptTypeP2SH     ScriptType = "p2sh"     // TX_SCRIPTHASH
	ScriptTypeP2SHW    ScriptType = "p2wsh"    // TX_WITNESS_V0_SCRIPTHASH
	ScriptTypeMultiSig ScriptType = "multisig" // TX_MULTISIG
	ScriptTypeNullData ScriptType = "nulldata" // TX_NULL_DATA
	ScriptTypeCustom   ScriptType = "custom"   // TX_NONSTANDARD
)

ScriptType constants - stored in gigawallet database!

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL