core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 21 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRejectedOutPoint  = errors.New("RejectedOutPoint")
	ErrInsufficientFunds = errors.New("InsufficientFunds")
	ErrNotEnoughChange   = errors.New("NotEnoughChange")
)
View Source
var (
	DasContractMap           syncmap.Map                               // map[contact name]{contract info}
	DasContractByTypeIdMap   = make(map[string]common.DasContractName) // map[contract type id]{contract name}
	DasConfigCellMap         syncmap.Map                               // map[ConfigCellTypeArgs]config cell info
	DasConfigCellByTxHashMap syncmap.Map                               // map[tx hash]{true}
	DasSoScriptMap           syncmap.Map                               // map[so script type]
)
View Source
var EnvMainNet = Env{
	THQCodeHash:      "0x9e537bf5b8ec044ca3f53355e879f3fd8832217e4a9b41d9994cf0c547241a79",
	ContractArgs:     "0xc126635ece567c71c50f7482c5db80603852c306",
	ContractCodeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
	MapContract: map[common.DasContractName]string{
		common.DasContractNameConfigCellType:        "0x3775c65aabe8b79980c4933dd2f4347fa5ef03611cef64328685618aa7535794",
		common.DasContractNameAccountCellType:       "0x96dc231bbbee6aa474076468640f9e0ad27cf13b1343716a7ce04b116ea18ba8",
		common.DasContractNameBalanceCellType:       "0xbdc8f42643ccad23e8df3d2e8dbdea9201812cd1b7f84c46e69b020529629822",
		common.DasContractNameDispatchCellType:      "0xda22fd296682488687a6035b5fc97c269b72d7de128034389bd03041b40309c0",
		common.DasContractNameIncomeCellType:        "0x108fba6a9b9f2898b4cdf11383ba2a6ed3da951b458c48e5f5de0353bbca2d46",
		common.DasContractNameAccountSaleCellType:   "0xb782d5f4e24603340997494871ba8f7d175e6920e63ead6b8137170b2e370469",
		common.DasContractNameAlwaysSuccess:         "0xca5016f232830f8a73e6827b5e1108aca68e7cf8baea4847ac40ef1da43c4c50",
		common.DasContractNameApplyRegisterCellType: "0xf18c3eab9fd28adbb793c38be9a59864989c1f739c22d2b6dc3f4284f047a69d",
		common.DasContractNamePreAccountCellType:    "0xf6574955079797010689a22cd172ce55b52d2c34d1e9bc6596e97babc2906f7e",
		common.DasContractNameProposalCellType:      "0xd7b779b1b30f86a77db6b292c9492906f2437b7d88a8a5994e722619bb1d41c8",
		common.DasContractNameReverseRecordCellType: "0x000f3e1a89d85d268ed6d36578d474ecf91d8809f4f696dd2e5b97fe67b84a2e",
		common.DASContractNameOfferCellType:         "0x3ffc0f8b0ce4bc09f700ca84355a092447d79fc5224a6fbd64af95af840af91b",
		common.DASContractNameSubAccountCellType:    "0x97b19f14184f24d55b1247596a5d7637f133c7bb7735f0ae962dc709c5fc1e2e",
		common.DASContractNameEip712LibCellType:     "0xa71fc12ca4ce4127dc911dbe8006f1907c850957849e282ef1f26e3ee50ba7bf",
	},
}
View Source
var EnvTestnet2 = Env{
	THQCodeHash:      "0x96248cdefb09eed910018a847cfb51ad044c2d7db650112931760e3ef34a7e9a",
	ContractArgs:     "0xbc502a34a430e3e167c82a24db6f9237b15ebf35",
	ContractCodeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
	MapContract: map[common.DasContractName]string{
		common.DasContractNameConfigCellType:        "0x34363fad2018db0b3b6919c26870f302da74c3c4ef4456e5665b82c4118eda51",
		common.DasContractNameAccountCellType:       "0x6f0b8328b703617508d62d1f017b0d91fab2056de320a7b7faed4c777a356b7b",
		common.DasContractNameBalanceCellType:       "0x27560fe2daa6150b771621300d1d4ea127832b7b326f2d70eed63f5333b4a8a9",
		common.DasContractNameDispatchCellType:      "0xeedd10c7d8fee85c119daf2077fea9cf76b9a92ddca546f1f8e0031682e65aee",
		common.DasContractNameIncomeCellType:        "0xd7b9d8213671aec03f3a3ab95171e0e79481db2c084586b9ea99914c00ff3716",
		common.DasContractNameAccountSaleCellType:   "0xed5d7fc00a3f8605bfe3f6717747bb0ed529fa064c2b8ce56e9677a0c46c2c1c",
		common.DasContractNameAlwaysSuccess:         "0x7821c662b7efd50e7f6cf2b036efe53e07eccaf2e3447a2a470ee07ae455ab92",
		common.DasContractNameApplyRegisterCellType: "0xc78fa9066af1624e600ccfb21df9546f900b2afe5d7940d91aefc115653f90d9",
		common.DasContractNamePreAccountCellType:    "0xd3f7ad59632a2ebdc2fe9d41aa69708ed1069b074cd8b297b205f835335d3a6b",
		common.DasContractNameProposalCellType:      "0x03d0bb128bd10e666975d9a07c148f6abebe811f511e9574048b30600b065b9a",
		common.DasContractNameReverseRecordCellType: "0x334d7841eb156b8aa5abd7b09277e91e782d840140905496bb5bff0ea6ce9d75",
		common.DASContractNameOfferCellType:         "0x443b2d1b3b00ffab1a2287d84c47b2c31a11aad24b183d732c213a69e3d6d390",
		common.DASContractNameSubAccountCellType:    "0x63ca3e26cc69809f06735c6d9139ec2d84f2a277f13509a54060d6ee19423b5b",
		common.DASContractNameEip712LibCellType:     "0x16549cab7e92afb5f157141bc9da7781ce692a3144e47e2b8879a8d5a57b87c6",
	},
}
View Source
var EnvTestnet3 = Env{
	THQCodeHash:      "0x96248cdefb09eed910018a847cfb51ad044c2d7db650112931760e3ef34a7e9a",
	ContractArgs:     "0xbc502a34a430e3e167c82a24db6f9237b15ebf35",
	ContractCodeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
	MapContract: map[common.DasContractName]string{
		common.DasContractNameConfigCellType:        "0xe9fa679290f63ba1debc74f04e96f299d1b61a03a24e7a1a51c7ccad416ec16a",
		common.DasContractNameAccountCellType:       "0x1c7d62798d412351ec9a4262aacc2c2837712b780d90e0720051ffa6d6304e32",
		common.DasContractNameBalanceCellType:       "0x301127f501c2620174b60945f305d78a4f5cdf67dd44009001265ca133d0088d",
		common.DasContractNameDispatchCellType:      "0xeedd10c7d8fee85c119daf2077fea9cf76b9a92ddca546f1f8e0031682e65aee",
		common.DasContractNameIncomeCellType:        "0x0af1f2332b1f742136ef0ffec849d415c4b5b8c4426de5d245f2e7ac0a9f5773",
		common.DasContractNameAccountSaleCellType:   "0xaf446d756fca5b51fad915a3f0526221527f1dd5f32898408ee86e73dc9d9814",
		common.DasContractNameAlwaysSuccess:         "0x7821c662b7efd50e7f6cf2b036efe53e07eccaf2e3447a2a470ee07ae455ab92",
		common.DasContractNameApplyRegisterCellType: "0xb12e454a3896b910030e669e8a81bf99c351cb58be8d1529e1c7023265db6084",
		common.DasContractNamePreAccountCellType:    "0x919e8036ded6670b923958db207527b5d1d3b95955e446e3475bfd7f949898c1",
		common.DasContractNameProposalCellType:      "0x2eecc2c70936609d14872acdedc9ba8b265c26240d49d66b6db027c5cfdb4256",
		common.DasContractNameReverseRecordCellType: "0x80963278cbdc61cdafd5250555984b71ad016798b8879adc0e6b1ee7e01b7912",
		common.DASContractNameOfferCellType:         "0xc69186c17e41fead0f87eb1f94829778e98a398be202655ac59fdb9567d05bae",
		common.DASContractNameSubAccountCellType:    "0x57498a2df0c0137146ced681fa1854599e404da5804c1a5ff45d954c3cc89bfd",
		common.DASContractNameEip712LibCellType:     "0xd21b1f02b6057d6776bf7f1c7a26f550f1b383a930349620507f328e4cc07f2e",
	},
}

Functions

func GetSatisfiedCapacityLiveCell

func GetSatisfiedCapacityLiveCell(client rpc.Client, dasCache *dascache.DasCache, dasLockScript, dasTypeScript *types.Script, capacityNeed, capacityForChange uint64) ([]*indexer.LiveCell, uint64, error)

func GetSatisfiedCapacityLiveCellWithOrder

func GetSatisfiedCapacityLiveCellWithOrder(client rpc.Client, dasCache *dascache.DasCache, dasLockScript, dasTypeScript *types.Script, capacityNeed, capacityForChange uint64, order indexer.SearchOrder) ([]*indexer.LiveCell, uint64, error)

func GetSatisfiedLimitLiveCell

func GetSatisfiedLimitLiveCell(client rpc.Client, dasCache *dascache.DasCache, searchKey *indexer.SearchKey, needLimit uint64, order indexer.SearchOrder) ([]*indexer.LiveCell, error)

func SetLogLevel

func SetLogLevel(level int)

func SplitOutputCell

func SplitOutputCell(total, base, limit uint64, lockScript, typeScript *types.Script) ([]*types.CellOutput, error)

func UpdateAccountCellDasLockToEip712

func UpdateAccountCellDasLockToEip712(cell *indexer.LiveCell) error

Types

type ChainTypeAddress

type ChainTypeAddress struct {
	Type    string  `json:"type"` // blockchain
	KeyInfo KeyInfo `json:"key_info"`
}

func (*ChainTypeAddress) FormatChainTypeAddress

func (c *ChainTypeAddress) FormatChainTypeAddress(net common.DasNetType, is712 bool) (*DasAddressHex, error)

type DasAddressFormat

type DasAddressFormat struct {
	DasNetType common.DasNetType
}

func (*DasAddressFormat) ArgsToHex

func (d *DasAddressFormat) ArgsToHex(args []byte) (ownerHex, managerHex DasAddressHex, e error)

only for .bit args

func (*DasAddressFormat) ArgsToNormal

func (d *DasAddressFormat) ArgsToNormal(args []byte) (ownerNormal, managerNormal DasAddressNormal, e error)

only for .bit args

func (*DasAddressFormat) HexToArgs

func (d *DasAddressFormat) HexToArgs(owner, manager DasAddressHex) (args []byte, e error)

only for .bit hex address

func (*DasAddressFormat) HexToHalfArgs

func (d *DasAddressFormat) HexToHalfArgs(p DasAddressHex) (args []byte, e error)

only for .bit hex address

func (*DasAddressFormat) HexToNormal

func (d *DasAddressFormat) HexToNormal(p DasAddressHex) (r DasAddressNormal, e error)

only for .bit hex address

func (*DasAddressFormat) HexToScript

func (d *DasAddressFormat) HexToScript(p DasAddressHex) (lockScript, typeScript *types.Script, e error)

only for .bit hex address

func (*DasAddressFormat) NormalToHex

func (d *DasAddressFormat) NormalToHex(p DasAddressNormal) (r DasAddressHex, e error)

only for .bit normal address

func (*DasAddressFormat) ScriptToHex

func (d *DasAddressFormat) ScriptToHex(s *types.Script) (ownerHex, managerHex DasAddressHex, e error)

for .bit or normal ckb script

type DasAddressHex

type DasAddressHex struct {
	DasAlgorithmId common.DasAlgorithmId
	AddressHex     string
	IsMulti        bool
	ChainType      common.ChainType // format normal address ckb chain type
}

type DasAddressNormal

type DasAddressNormal struct {
	ChainType     common.ChainType
	AddressNormal string
	Is712         bool
}

type DasConfigCellInfo

type DasConfigCellInfo struct {
	Name        string
	OutPoint    types.OutPoint
	BlockNumber uint64
}

config cell info

func GetDasConfigCellInfo

func GetDasConfigCellInfo(configCellTypeArgs common.ConfigCellTypeArgs) (*DasConfigCellInfo, error)

func (*DasConfigCellInfo) ToCellDep

func (d *DasConfigCellInfo) ToCellDep() *types.CellDep

type DasContractInfo

type DasContractInfo struct {
	ContractName   common.DasContractName
	OutPoint       *types.OutPoint   // contract outpoint
	OutPut         *types.CellOutput // contract script
	ContractTypeId types.Hash        // contract type id
}

func GetDasContractInfo

func GetDasContractInfo(contractName common.DasContractName) (*DasContractInfo, error)

func (*DasContractInfo) IsSameTypeId

func (d *DasContractInfo) IsSameTypeId(codeHash types.Hash) bool

func (*DasContractInfo) ToCellDep

func (d *DasContractInfo) ToCellDep() *types.CellDep

func (*DasContractInfo) ToScript

func (d *DasContractInfo) ToScript(args []byte) *types.Script

type DasCore

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

func NewDasCore

func NewDasCore(ctx context.Context, wg *sync.WaitGroup, opts ...DasCoreOption) *DasCore

func (*DasCore) AsyncDasConfigCell

func (d *DasCore) AsyncDasConfigCell() error

func (*DasCore) Client

func (d *DasCore) Client() rpc.Client

func (*DasCore) ConfigCellDataBuilderByTypeArgs

func (d *DasCore) ConfigCellDataBuilderByTypeArgs(configCellTypeArgs common.ConfigCellTypeArgs) (*witness.ConfigCellDataBuilder, error)

func (*DasCore) ConfigCellDataBuilderByTypeArgsList

func (d *DasCore) ConfigCellDataBuilderByTypeArgsList(list ...common.ConfigCellTypeArgs) (*witness.ConfigCellDataBuilder, error)

func (*DasCore) Daf

func (d *DasCore) Daf() *DasAddressFormat

func (*DasCore) GetAccountCellOnChainByAlgorithmId

func (d *DasCore) GetAccountCellOnChainByAlgorithmId(oID, mID common.DasAlgorithmId, oA, mA, account string) (*indexer.LiveCell, error)

func (*DasCore) GetBalanceCells

func (d *DasCore) GetBalanceCells(p *ParamGetBalanceCells) ([]*indexer.LiveCell, uint64, error)

func (*DasCore) GetCustomScriptLiveCell

func (d *DasCore) GetCustomScriptLiveCell(data []byte) (*indexer.LiveCell, error)

func (*DasCore) GetDasLock

func (d *DasCore) GetDasLock() *types.Script

func (*DasCore) GetHeightCell

func (d *DasCore) GetHeightCell() (*HeightCell, error)

func (*DasCore) GetQuoteCell

func (d *DasCore) GetQuoteCell() (*QuoteCell, error)

func (*DasCore) GetSubAccountCell

func (d *DasCore) GetSubAccountCell(parentAccountId string) (*indexer.LiveCell, error)

func (*DasCore) GetTimeCell

func (d *DasCore) GetTimeCell() (*TimeCell, error)

func (*DasCore) InitDasConfigCell

func (d *DasCore) InitDasConfigCell() error

func (*DasCore) InitDasContract

func (d *DasCore) InitDasContract(mapDasContractTypeArgs map[common.DasContractName]string)

func (*DasCore) InitDasSoScript

func (d *DasCore) InitDasSoScript() error

func (*DasCore) NetType

func (d *DasCore) NetType() common.DasNetType

func (*DasCore) RunAsyncDasConfigCell

func (d *DasCore) RunAsyncDasConfigCell(t time.Duration)

func (*DasCore) RunAsyncDasContract

func (d *DasCore) RunAsyncDasContract(t time.Duration)

update contract info

func (*DasCore) RunAsyncDasSoScript

func (d *DasCore) RunAsyncDasSoScript(t time.Duration)

func (*DasCore) UpdateAccountCellDasLockToEip712

func (d *DasCore) UpdateAccountCellDasLockToEip712(cell *indexer.LiveCell)

type DasCoreOption

type DasCoreOption func(*DasCore)

func WithClient

func WithClient(client rpc.Client) DasCoreOption

func WithDasContractArgs

func WithDasContractArgs(dasContractArgs string) DasCoreOption

func WithDasContractCodeHash

func WithDasContractCodeHash(dasContractCodeHash string) DasCoreOption

func WithDasNetType

func WithDasNetType(net common.DasNetType) DasCoreOption

func WithTHQCodeHash

func WithTHQCodeHash(thqCodeHash string) DasCoreOption

type Env

type Env struct {
	THQCodeHash      string
	ContractArgs     string
	ContractCodeHash string
	MapContract      map[common.DasContractName]string
}

func InitEnv

func InitEnv(net common.DasNetType) Env

func InitEnvOpt

func InitEnvOpt(net common.DasNetType, names ...common.DasContractName) Env

type HeightCell

type HeightCell struct {
	LiveCell *indexer.LiveCell
}

func (*HeightCell) BlockNumber

func (t *HeightCell) BlockNumber() int64

func (*HeightCell) ToCellDep

func (t *HeightCell) ToCellDep() *types.CellDep

type KeyInfo

type KeyInfo struct {
	CoinType common.CoinType `json:"coin_type"`
	ChainId  common.ChainId  `json:"chain_id"`
	Key      string          `json:"key"`
}

type ParamGetBalanceCells

type ParamGetBalanceCells struct {
	DasCache          *dascache.DasCache
	LockScript        *types.Script
	CapacityNeed      uint64
	CapacityForChange uint64
	SearchOrder       indexer.SearchOrder
}

type QuoteCell

type QuoteCell struct {
	LiveCell *indexer.LiveCell
}

func (*QuoteCell) Quote

func (q *QuoteCell) Quote() uint64

func (*QuoteCell) ToCellDep

func (q *QuoteCell) ToCellDep() *types.CellDep

type SoScript

type SoScript struct {
	Name     common.SoScriptType
	OutPoint types.OutPoint
}

func GetDasSoScript

func GetDasSoScript(soScriptName common.SoScriptType) (*SoScript, error)

func (*SoScript) ToCellDep

func (d *SoScript) ToCellDep() *types.CellDep

type TimeCell

type TimeCell struct {
	LiveCell *indexer.LiveCell
}

func (*TimeCell) Timestamp

func (t *TimeCell) Timestamp() int64

func (*TimeCell) ToCellDep

func (t *TimeCell) ToCellDep() *types.CellDep

Jump to

Keyboard shortcuts

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