Documentation ¶
Index ¶
- Constants
- func Base32Encode(md32 []uint8) string
- func ConvertAddress2pubk(address string) (string, error)
- func CopyReverse(bs []byte) []byte
- func CopyReverseThenEncodeHex(bs []byte) string
- func CryptoMultiSign(pubks [][]byte, privk ed25519.PrivateKey, msg []byte, currentSig []byte) ([]byte, error)
- func GetPubKeyAddress(pubk string) (string, error)
- func JSONIndent(v interface{}) string
- func ParsePrivkHex(privkHex string) (ed25519.PrivateKey, error)
- func ParsePublicKeyHex(hexedPubK string) ([]byte, error)
- func PrivateKeyHex2Seed(hexedPrivk string) ([]byte, error)
- func Seed2pubk(seed []byte) ([]byte, error)
- func Seed2pubkString(seed []byte) (string, error)
- func Seed2string(seed []byte) string
- func UntilError(fns ...func() error) error
- func UtilDataEncoding(data string) string
- type AddrKeyPair
- type DataDetail
- type MultisigInfo
- type MultisigMember
- type RawTransaction
- func (rtx *RawTransaction) Encode(encodeSignData bool) (string, error)
- func (rtx *RawTransaction) EncodeBytes(encodeSignData bool) ([]byte, error)
- func (rtx *RawTransaction) SignWithPrivateKey(templateDataList, privkHex string) error
- func (rtx RawTransaction) ToTransaction(includeSignData bool) Transaction
- func (rtx *RawTransaction) Txid() ([32]byte, error)
- type TW
- func (tw *TW) Continue(_continue bool) *TW
- func (tw *TW) Copy() *TW
- func (tw *TW) Equal(expected, actual interface{}, args ...interface{}) *TW
- func (tw *TW) IsZero(v interface{}, args ...interface{}) *TW
- func (tw *TW) Nil(x interface{}, args ...interface{}) *TW
- func (tw *TW) NotZero(v interface{}, args ...interface{}) *TW
- func (tw *TW) True(flag bool, args ...interface{}) *TW
- type TXBuilder
- func (b *TXBuilder) AddInput(txid string, vout uint8) *TXBuilder
- func (b *TXBuilder) Build() (*RawTransaction, error)
- func (b *TXBuilder) SetAddress(add string) *TXBuilder
- func (b *TXBuilder) SetAmount(amount float64) *TXBuilder
- func (b *TXBuilder) SetAnchor(anchor string) *TXBuilder
- func (b *TXBuilder) SetData(data []byte) *TXBuilder
- func (b *TXBuilder) SetDataWithUUID(_uuid string, timestamp int64, data string) *TXBuilder
- func (b *TXBuilder) SetFee(fee float64) *TXBuilder
- func (b *TXBuilder) SetLockUntil(lockUntil int) *TXBuilder
- func (b *TXBuilder) SetStringData(data string) *TXBuilder
- func (b *TXBuilder) SetTimestamp(timestamp int) *TXBuilder
- func (b *TXBuilder) SetVersion(v int) *TXBuilder
- type TXData
- type TemplateType
- type Transaction
- type Vin
Constants ¶
const ( PubkeyHexLen = 32*2 + 1 PrivkeyHexLen = 32*2 + 1 PubkeyAddressLen = 57 + 1 Uint256HexLen = 65 )
some len const
const Precision = 1000000
const TemplateDataSpliter = ","
TemplateDataSpliter 使用,分隔多个template data
Variables ¶
This section is empty.
Functions ¶
func ConvertAddress2pubk ¶ added in v1.0.7
ConvertAddress2pubk .
func CopyReverseThenEncodeHex ¶
CopyReverseThenEncodeHex 复制[]byte,反转后hex.EncodeToString
func CryptoMultiSign ¶
func CryptoMultiSign(pubks [][]byte, privk ed25519.PrivateKey, msg []byte, currentSig []byte) ([]byte, error)
CryptoMultiSign pubks 公钥数组,privk 私钥, msg 待签名数据, sig 已有签名
func GetPubKeyAddress ¶
GetPubKeyAddress Get Address hex string from public key hex string
func ParsePrivkHex ¶
func ParsePrivkHex(privkHex string) (ed25519.PrivateKey, error)
ParsePrivkHex BBC 私钥解析为ed25519.PrivateKey
func ParsePublicKeyHex ¶
ParsePublicKeyHex 解析私钥为实际使用的seed
func PrivateKeyHex2Seed ¶
PrivateKeyHex2Seed 解析私钥为实际使用的seed
func UntilError ¶
UntilError execute all func until error returned
func UtilDataEncoding ¶ added in v1.0.7
UtilDataEncoding 将tx data 进行编码
Types ¶
type AddrKeyPair ¶
AddrKeyPair 地址、私钥、公钥
type DataDetail ¶ added in v1.0.7
DataDetail .
func UtilDataDecoding ¶ added in v1.0.7
func UtilDataDecoding(data string) (DataDetail, error)
UtilDataDecoding .
type MultisigInfo ¶
type MultisigInfo struct { Hex string M, N uint8 //m-n签名,N名成员需要至少M个签名 Members []MultisigMember }
MultisigInfo 多签信息
func ParseMultisigTemplateHex ¶
func ParseMultisigTemplateHex(hexData string) (*MultisigInfo, error)
ParseMultisigTemplateHex 解析多签地址hex, hex decode 前2byte代表类型,通常是0200 (不确定是0200或者0020) 接下来1+8 byte为M,N 接下来有N个33 (32为公钥,1为weight) ref to: https://github.com/bigbangcore/BigBang/wiki/%E5%A4%9A%E9%87%8D%E7%AD%BE%E5%90%8D |---2---|---1---|---8---|---33*n---| | type | M | N | keys... |
func (MultisigInfo) SignTemplatePart ¶
func (mi MultisigInfo) SignTemplatePart() []byte
SignTemplatePart 签名时签名的前半部分
type RawTransaction ¶
type RawTransaction struct { Version uint16 Typ uint16 //type > typ Timestamp uint32 LockUntil uint32 HashAnchorBytes [32]byte `json:"-"` // fork id SizeIn uint64 //input 数量 Input []byte `json:"-"` Prefix uint8 //addr prefix AddressBytes [32]byte `json:"-"` // binary data (caller do not care about this field, you just care hex field) Amount int64 TxFee int64 SizeOut uint64 VchData []byte `json:"-"` // binary (caller do not care about this field, you just care hex field) SizeSign uint64 // binary sign data size, ref: https://github.com/bigbangcore/BigBang/wiki/IO-Stream#stdvector-stdmap-stdstring SignBytes []byte `json:"-"` // [template data]sig }
RawTransaction 实际的序列话数据结构 注意:数据类型不要更改(序列化时对类型有依赖)
func (*RawTransaction) Encode ¶
func (rtx *RawTransaction) Encode(encodeSignData bool) (string, error)
Encode .
func (*RawTransaction) EncodeBytes ¶
func (rtx *RawTransaction) EncodeBytes(encodeSignData bool) ([]byte, error)
EncodeBytes .
func (*RawTransaction) SignWithPrivateKey ¶ added in v1.0.3
func (rtx *RawTransaction) SignWithPrivateKey(templateDataList, privkHex string) error
SignWithPrivateKey 用私钥签名 templateDataList: 使用[,]分隔的模版数据列表, - 对于不需要模版数据的交易传入空字符串即可, - 如果传入了模版数据签名后会将模版数据按照顺序放在签名前面, - 如果传入的模版数据检测到多重签名则在签名时使用多重签名机制
通常,在from为模版地址时需要传入from的模版数据,可以通过rpc validateaddress 获取(data.addressdata.templatedata.hex) 当to地址为vote类型模版地址时需要传入to地址模版数据 特别的,只有1种情况需要传入2个模版地址:delegate类型模版的owner为多签地址,从该地址转出时需要传入:delegate模版数据,多签模版数据 (基于上面一种情况,如果转出地址为vote template可能还需要提供vote template data, 一共3个😂,这个未经测试、验证)
下面列出常见的场景: 一般公钥地址转出(到非vote template)->(不需要模版数据) 一般公钥地址投票时->投票模版数据 一般公钥投票赎回时->投票模版数据 多签地址签名(转账到一般地址)->多签模版数据 从dpos委托模版地址转出->委托模版数据 从dpos委托模版(owner为多签)地址转出->委托模版数据+多签模版数据 从pow挖矿模版地址转出->pow挖矿模版地址
注意:签名逻辑不对模版数据进行严格合理的校验,因为离线环境下无法感知模版数据的有效性,调用方需自行确保参数正确
func (RawTransaction) ToTransaction ¶ added in v1.0.7
func (rtx RawTransaction) ToTransaction(includeSignData bool) Transaction
ToTransaction .
type TW ¶
TW testing.T wrap
type TXBuilder ¶ added in v1.0.7
type TXBuilder struct {
// contains filtered or unexported fields
}
TXBuilder .
func NewTXBuilder ¶ added in v1.0.7
func NewTXBuilder() *TXBuilder
func (*TXBuilder) Build ¶ added in v1.0.7
func (b *TXBuilder) Build() (*RawTransaction, error)
Build .
func (*TXBuilder) SetAddress ¶ added in v1.0.7
SetAddress 转账地址,目前只支持公钥地址
func (*TXBuilder) SetDataWithUUID ¶ added in v1.0.7
SetDataWithUUID 指定uuid,timestamp,data
func (*TXBuilder) SetLockUntil ¶ added in v1.0.7
SetLockUntil lock until
func (*TXBuilder) SetStringData ¶ added in v1.0.7
SetStringData 自动编码数据,自动生成uuid和时间戳
func (*TXBuilder) SetTimestamp ¶ added in v1.0.7
SetTimestamp 当前时间戳
func (*TXBuilder) SetVersion ¶ added in v1.0.7
SetVersion 当前版本 1
type TXData ¶ added in v1.0.5
type TXData struct { TplHex string `json:"tpl_hex,omitempty"` //成员信息,通过rpc validateaddress (多签模版地址) 取到的值的ret.Addressdata.Templatedata.Hex TxHex string `json:"tx_hex,omitempty"` //encoded tx data }
TXData 包含了原始交易数据和需要的模版数据,模版数据使用,(英文逗号)分隔
func (*TXData) DecodeString ¶ added in v1.0.8
DecodeString parse jsonHex set value to data
func (*TXData) EncodeString ¶ added in v1.0.8
EncodeString json marshal + hex encode
type TemplateType ¶ added in v1.0.3
type TemplateType int16
TemplateType 模版类型
const ( TemplateTypeMin TemplateType = iota TemplateTypeWeighted TemplateTypeMultisig //多重签名 TemplateTypeFork TemplateTypeProof //pow TemplateTypeDelegate //dpos TemplateTypeExchange TemplateTypeVote //dpos投票 TemplateTypePayment TemplateTypeMax )
模版类型
func GetTemplateType ¶ added in v1.0.3
func GetTemplateType(templateData string) TemplateType
GetTemplateType 如果解析失败则返回TemplateTypeMin(0)
func (TemplateType) String ¶ added in v1.0.5
func (typ TemplateType) String() string
type Transaction ¶
type Transaction struct { RawTransaction HashAnchor string // hex string([65]byte) Address string // hex string ([64 + 1]byte) Sign string // hex string Vin []Vin Data string }
Transaction . TODO 增加vout
func DecodeRawTransaction ¶
func DecodeRawTransaction(txData string, decodeSignData bool) (*Transaction, error)
DecodeRawTransaction hexed tx parse