tokenengine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: GPL-3.0, GPL-3.0 Imports: 11 Imported by: 2

README

Token Engine介绍

TokenEngine来自于btcd的txscript模块,该模块实现了比特币的堆栈引擎。对于txscript项目做了如下修改:

  1. 屏蔽了隔离见证相关的代码。
  2. 修改了Tx结构,采用了Tx->Message->Input/Output这样的三层结构
  3. 增加了OPCODE:OP_JURY_REDEEM_EQUAL = 0xc8 // 200 用于从状态数据库获得一个合约的陪审团赎回代码并判断是否相等。
  4. 增加了SigHashRaw SigHashType = 0x4 //直接对构造好的不包含任何签名信息的Tx签名
  5. 增加了付款到合约和从合约付款出去的支持。

Documentation

Index

Constants

View Source
const (
	SigHashOld          uint32 = 0x0
	SigHashAll          uint32 = 0x1
	SigHashNone         uint32 = 0x2
	SigHashSingle       uint32 = 0x3
	SigHashRaw          uint32 = 0x4
	SigHashAnyOneCanPay uint32 = 0x80
)

Variables

This section is empty.

Functions

func CalcSignatureHash

func CalcSignatureHash(tx *modules.Transaction, hashType uint32, msgIdx, inputIdx int, lockOrRedeemScript []byte) ([]byte, error)

为钱包计算要签名某个Input对应的Hash

func DisasmString

func DisasmString(script []byte) (string, error)

传入一个脚本二进制,解析为可读的文本形式

func GenerateLockScript

func GenerateLockScript(address common.Address) []byte

根据地址产生对应的锁定脚本

func GenerateP2CHLockScript

func GenerateP2CHLockScript(contractId common.Address) []byte

func GenerateP2CHUnlockScript

func GenerateP2CHUnlockScript(signs [][]byte, redeemScript []byte) []byte

根据收集到的签名和脚本生成解锁合约上的Token的脚本

func GenerateP2PKHLockScript

func GenerateP2PKHLockScript(pubKeyHash []byte) []byte

Generate a P2PKH lock script, just only need input 20bytes public key hash. You can use Address.Bytes() to get address hash.

func GenerateP2PKHUnlockScript

func GenerateP2PKHUnlockScript(sign []byte, pubKey []byte) []byte

根据签名和公钥信息生成解锁脚本 Use signature and public key to generate a P2PKH unlock script

func GenerateP2SHLockScript

func GenerateP2SHLockScript(redeemScriptHash []byte) []byte

Give redeem script hash 160 result, generate a P2SH lock script. If you have built your redeem script, please use crypto.Hash160() to gnerate hash

func GenerateP2SHUnlockScript

func GenerateP2SHUnlockScript(signs [][]byte, redeemScript []byte) []byte

根据收集到的签名和脚本生成解锁脚本 Use collection signatures and redeem script to unlock

func GenerateRedeemScript

func GenerateRedeemScript(needed byte, pubKeys [][]byte) []byte

生成多签用的赎回脚本 Generate redeem script

func GetAddressFromScript

func GetAddressFromScript(lockScript []byte) (common.Address, error)

根据锁定脚本获得对应的地址

func GetScriptSigners

func GetScriptSigners(tx *modules.Transaction, msgIdx, inputIndex int) ([]common.Address, error)

对于一个多签或者合约解锁脚本,获得到底哪些用户参与了签名

func IsUnspendable

func IsUnspendable(script []byte) bool

func MergeContractUnlockScript

func MergeContractUnlockScript(signs [][]byte, redeemScript []byte) []byte

func MultiSignOnePaymentInput

func MultiSignOnePaymentInput(tx *modules.Transaction, hashType uint32, msgIdx, id int, utxoLockScript []byte, redeemScript []byte,
	pubKeyFn AddressGetPubKey, hashFn AddressGetSign, previousScript []byte) ([]byte, error)

对交易中的Payment类型中的某个Input生成解锁脚本

func SignOnePaymentInput(tx *modules.Transaction, msgIdx, id int, utxoLockScript []byte, privKey *ecdsa.PrivateKey, juryVersion int) ([]byte, error) {
	lookupKey := func(a common.Address) (*ecdsa.PrivateKey, bool, error) {
		return privKey, true, nil
	}
	sigScript, err := txscript.SignTxOutput(tx, msgIdx, id, utxoLockScript, txscript.SigHashAll,
		txscript.KeyClosure(lookupKey), nil, nil, juryVersion)
	if err != nil {
		return []byte{}, err
	}
	return sigScript, nil
}

func ScriptValidate

func ScriptValidate(utxoLockScript []byte, pickupJuryRedeemScript txscript.PickupJuryRedeemScript, tx *modules.Transaction, msgIdx, inputIndex int) error

validate this transaction and input index script can unlock the utxo.

func SignTxAllPaymentInput

func SignTxAllPaymentInput(tx *modules.Transaction, hashType uint32, utxoLockScripts map[modules.OutPoint][]byte,
	redeemScript []byte, pubKeyFn AddressGetPubKey, hashFn AddressGetSign) ([]common.SignatureError, error)

Sign a full transaction

Types

type AddressGetPubKey

type AddressGetPubKey func(common.Address) ([]byte, error)

type AddressGetSign

type AddressGetSign func(common.Address, []byte) ([]byte, error)

type PubKey4Sort

type PubKey4Sort [][]byte

func (PubKey4Sort) Len

func (c PubKey4Sort) Len() int

func (PubKey4Sort) Less

func (c PubKey4Sort) Less(i, j int) bool

func (PubKey4Sort) Swap

func (c PubKey4Sort) Swap(i, j int)

Directories

Path Synopsis
internal
txscript
Package txscript implements the bitcoin transaction script language.
Package txscript implements the bitcoin transaction script language.

Jump to

Keyboard shortcuts

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