diff --git a/address/address.go b/address/address.go index 8ced2130..0fe0a748 100644 --- a/address/address.go +++ b/address/address.go @@ -213,6 +213,8 @@ func toHrp(network types.Network) (string, error) { return "ckb", nil case types.NetworkTest: return "ckt", nil + case types.NetworkPreview: + return "ckt", nil default: return "", errors.New("unknown network") } diff --git a/collector/builder/builder.go b/collector/builder/builder.go index 5cf6288c..e4a215a2 100644 --- a/collector/builder/builder.go +++ b/collector/builder/builder.go @@ -30,7 +30,7 @@ type SimpleTransactionBuilder struct { // // To create an empty builder without script handlers, just uses '&SimpleTransactionBuilder{}'. func NewSimpleTransactionBuilder(network types.Network) *SimpleTransactionBuilder { - if network == types.NetworkMain || network == types.NetworkTest { + if network == types.NetworkMain || network == types.NetworkTest || network == types.NetworkPreview { s := SimpleTransactionBuilder{} s.Register(handler.NewSecp256k1Blake160SighashAllScriptHandler(network)) s.Register(handler.NewSecp256k1Blake160MultisigAllScriptHandler(network)) diff --git a/collector/handler/ckb.go b/collector/handler/ckb.go index 868a1b47..7e512295 100644 --- a/collector/handler/ckb.go +++ b/collector/handler/ckb.go @@ -19,6 +19,8 @@ func NewSecp256k1Blake160SighashAllScriptHandler(network types.Network) *Secp256 txHash = types.HexToHash("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c") } else if network == types.NetworkTest { txHash = types.HexToHash("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37") + } else if network == types.NetworkPreview { + txHash = types.HexToHash("0x0fab65924f2784f17ad7f86d6aef4b04ca1ca237102a68961594acebc5c77816") } else { return nil } @@ -66,6 +68,8 @@ func NewSecp256k1Blake160MultisigAllScriptHandler(network types.Network) *Secp25 txHash = types.HexToHash("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c") } else if network == types.NetworkTest { txHash = types.HexToHash("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37") + } else if network == types.NetworkPreview { + txHash = types.HexToHash("0x0fab65924f2784f17ad7f86d6aef4b04ca1ca237102a68961594acebc5c77816") } else { return nil } diff --git a/collector/handler/dao.go b/collector/handler/dao.go index d1ecd59a..39ab49d6 100644 --- a/collector/handler/dao.go +++ b/collector/handler/dao.go @@ -34,6 +34,8 @@ func NewDaoScriptHandler(network types.Network) *DaoScriptHandler { txHash = types.HexToHash("0xe2fb199810d49a4d8beec56718ba2593b665db9d52299a0f9e6e75416d73ff5c") } else if network == types.NetworkTest { txHash = types.HexToHash("0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f") + } else if network == types.NetworkPreview { + txHash = types.HexToHash("0xe93c55bea88e10c64d9b218ee2b504bc89b9e5ee912186ff904c1827360a5362") } else { return nil } diff --git a/collector/handler/omnilock.go b/collector/handler/omnilock.go index 98bac93e..459ab1af 100644 --- a/collector/handler/omnilock.go +++ b/collector/handler/omnilock.go @@ -64,6 +64,28 @@ func NewOmnilockScriptHandler(network types.Network) *OmnilockScriptHandler { }, CodeHash: systemscript.GetCodeHash(network, systemscript.Omnilock), } + case types.NetworkPreview: + return &OmnilockScriptHandler{ + SingleSignCellDep: &types.CellDep{ + OutPoint: &types.OutPoint{ + TxHash: types.HexToHash("0x0fab65924f2784f17ad7f86d6aef4b04ca1ca237102a68961594acebc5c77816"), + Index: 0, + }, + DepType: types.DepTypeDepGroup, + }, + MultiSignCellDep: &types.CellDep{ + OutPoint: &types.OutPoint{ + TxHash: types.HexToHash("0x0fab65924f2784f17ad7f86d6aef4b04ca1ca237102a68961594acebc5c77816"), + Index: 1, + }, + DepType: types.DepTypeDepGroup, + }, + CellDep: &types.CellDep{ + OutPoint: systemscript.GetInfo(network, systemscript.Omnilock).OutPoint, + DepType: systemscript.GetInfo(network, systemscript.Omnilock).DepType, + }, + CodeHash: systemscript.GetCodeHash(network, systemscript.Omnilock), + } default: return nil } diff --git a/crypto/bech32/bech32.go b/crypto/bech32/bech32.go index f57289f5..7bbc2047 100644 --- a/crypto/bech32/bech32.go +++ b/crypto/bech32/bech32.go @@ -11,7 +11,9 @@ const charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" var gen = []int{0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3} const BECH32M_CONST = 0x2bc830a3 + type Encoding uint + const ( BECH32 Encoding = iota BECH32M @@ -42,7 +44,7 @@ func Decode(bech string) (Encoding, string, []byte, error) { decoded, err := toBytes(data) if err != nil { - return BECH32, "", nil, errors.New(fmt.Sprintf("failed converting data to bytes: %v", err)) + return BECH32, "", nil, errors.New(fmt.Sprintf("failed converting data to bytes: %v", err)) } ints := make([]int, len(decoded)) diff --git a/crypto/secp256k1/key_test.go b/crypto/secp256k1/key_test.go index 34843739..8bb5191f 100644 --- a/crypto/secp256k1/key_test.go +++ b/crypto/secp256k1/key_test.go @@ -15,4 +15,4 @@ func TestPubKey(t *testing.T) { assert.Equal(t, common.FromHex("0x04a0a7a7597b019828a1dda6ed52ab25181073ec3a9825d28b9abbb932fe1ec83dd117a8eef7649c25be5a591d08f80ffe7e9c14100ad1b58ac78afa606a576453"), encoded) encoded = k.PubKey() assert.Equal(t, common.FromHex("0x03a0a7a7597b019828a1dda6ed52ab25181073ec3a9825d28b9abbb932fe1ec83d"), encoded) -} \ No newline at end of file +} diff --git a/indexer/indexer_test.go b/indexer/indexer_test.go index 4e4ec8eb..e83bff9b 100644 --- a/indexer/indexer_test.go +++ b/indexer/indexer_test.go @@ -78,7 +78,7 @@ func TestGetCellsMaxLimit(t *testing.T) { } resp, err := c.GetCells(context.Background(), s, SearchOrderAsc, math.MaxUint32, "") checkError(t, err) - // TODO fix later + // TODO fix later // assert.Equal(t, 36, len(resp.Objects)) // Check response when `WithData` == true in request diff --git a/mercury/client_test.go b/mercury/client_test.go index 9031b14d..d5c07f2d 100644 --- a/mercury/client_test.go +++ b/mercury/client_test.go @@ -1,323 +1,323 @@ package mercury -import ( - "github.com/nervosnetwork/ckb-sdk-go/v2/mercury/model" - "github.com/nervosnetwork/ckb-sdk-go/v2/types" - "github.com/stretchr/testify/assert" - "math/big" - "runtime/debug" - "testing" -) +// import ( +// "github.com/nervosnetwork/ckb-sdk-go/v2/mercury/model" +// "github.com/nervosnetwork/ckb-sdk-go/v2/types" +// "github.com/stretchr/testify/assert" +// "math/big" +// "runtime/debug" +// "testing" +// ) -var c, _ = Dial("https://mercury-testnet.ckbapp.dev/0.4") +// var c, _ = Dial("https://mercury-testnet.ckbapp.dev/0.4") -func TestBuildAdjustAccountTransaction(t *testing.T) { - item, err := model.NewIdentityItemByPublicKeyHash("0xb0f8a32e7f9e8f3ab3a641f6eb02fcdb921d5589") - checkError(t, err) - from, err := model.NewIdentityItemByPublicKeyHash("0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf") - checkError(t, err) - payload := &model.BuildAdjustAccountPayload{ - Item: item, - From: []*model.Item{from}, - AssetInfo: model.NewUdtAsset(types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd")), - AccountNumber: 1, - ExtraCKB: 20000000000, - FeeRate: 1000, - } - resp, err := c.BuildAdjustAccountTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) - assert.True(t, len(resp.ScriptGroups) >= 1) -} +// func TestBuildAdjustAccountTransaction(t *testing.T) { +// item, err := model.NewIdentityItemByPublicKeyHash("0xb0f8a32e7f9e8f3ab3a641f6eb02fcdb921d5589") +// checkError(t, err) +// from, err := model.NewIdentityItemByPublicKeyHash("0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf") +// checkError(t, err) +// payload := &model.BuildAdjustAccountPayload{ +// Item: item, +// From: []*model.Item{from}, +// AssetInfo: model.NewUdtAsset(types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd")), +// AccountNumber: 1, +// ExtraCKB: 20000000000, +// FeeRate: 1000, +// } +// resp, err := c.BuildAdjustAccountTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// assert.True(t, len(resp.ScriptGroups) >= 1) +// } -func TestGetBalance(t *testing.T) { - item, err := model.NewIdentityItemByPublicKeyHash("0x839f1806e85b40c13d3c73866045476cc9a8c214") - checkError(t, err) - payload := &model.GetBalancePayload{ - Item: item, - AssetInfos: []*model.AssetInfo{ - model.NewUdtAsset(types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"))}, - TipBlockNumber: 0, - } - resp, err := c.GetBalance(payload) - checkError(t, err) - assert.Equal(t, 2, len(resp.Balances)) - assert.Equal(t, types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"), - resp.Balances[0].AssetInfo.UdtHash) -} +// func TestGetBalance(t *testing.T) { +// item, err := model.NewIdentityItemByPublicKeyHash("0x839f1806e85b40c13d3c73866045476cc9a8c214") +// checkError(t, err) +// payload := &model.GetBalancePayload{ +// Item: item, +// AssetInfos: []*model.AssetInfo{ +// model.NewUdtAsset(types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"))}, +// TipBlockNumber: 0, +// } +// resp, err := c.GetBalance(payload) +// checkError(t, err) +// assert.Equal(t, 2, len(resp.Balances)) +// assert.Equal(t, types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"), +// resp.Balances[0].AssetInfo.UdtHash) +// } -func TestBuildSudtIssueTransaction(t *testing.T) { - address := "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf" - item, err := model.NewIdentityItemByAddress(address) - checkError(t, err) - payload := &model.BuildSudtIssueTransactionPayload{ - Owner: address, - From: []*model.Item{item}, - To: []*model.ToInfo{ - { - Address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv", - Amount: big.NewInt(1), - }, - }, - OutputCapacityProvider: model.OutputCapacityProviderFrom, - FeeRate: 1000, - } - resp, err := c.BuildSudtIssueTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) -} +// func TestBuildSudtIssueTransaction(t *testing.T) { +// address := "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf" +// item, err := model.NewIdentityItemByAddress(address) +// checkError(t, err) +// payload := &model.BuildSudtIssueTransactionPayload{ +// Owner: address, +// From: []*model.Item{item}, +// To: []*model.ToInfo{ +// { +// Address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv", +// Amount: big.NewInt(1), +// }, +// }, +// OutputCapacityProvider: model.OutputCapacityProviderFrom, +// FeeRate: 1000, +// } +// resp, err := c.BuildSudtIssueTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// } -func TestBuildSimpleTransferTransaction(t *testing.T) { - payload := &model.SimpleTransferPayload{ - AssetInfo: model.NewCkbAsset(), - From: []string{"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk"}, - To: []*model.ToInfo{ - { - Address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf", - Amount: big.NewInt(10000000000), - }, - }, - FeeRate: 500, - } - resp, err := c.BuildSimpleTransferTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) -} +// func TestBuildSimpleTransferTransaction(t *testing.T) { +// payload := &model.SimpleTransferPayload{ +// AssetInfo: model.NewCkbAsset(), +// From: []string{"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk"}, +// To: []*model.ToInfo{ +// { +// Address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf", +// Amount: big.NewInt(10000000000), +// }, +// }, +// FeeRate: 500, +// } +// resp, err := c.BuildSimpleTransferTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// } -func TestBuildTransferTransaction(t *testing.T) { - address := "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk" - item, err := model.NewAddressItem(address) - checkError(t, err) - payload := &model.TransferPayload{ - AssetInfo: model.NewCkbAsset(), - From: []*model.Item{item}, - To: []*model.ToInfo{ - { - Address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf", - Amount: big.NewInt(100), - }, - }, - PayFee: model.PayFeeFrom, - FeeRate: 1100, - } - resp, err := c.BuildTransferTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) -} +// func TestBuildTransferTransaction(t *testing.T) { +// address := "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk" +// item, err := model.NewAddressItem(address) +// checkError(t, err) +// payload := &model.TransferPayload{ +// AssetInfo: model.NewCkbAsset(), +// From: []*model.Item{item}, +// To: []*model.ToInfo{ +// { +// Address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf", +// Amount: big.NewInt(100), +// }, +// }, +// PayFee: model.PayFeeFrom, +// FeeRate: 1100, +// } +// resp, err := c.BuildTransferTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// } -func TestBuildDaoDepositTransaction(t *testing.T) { - from, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk") - checkError(t, err) - payload := &model.DaoDepositPayload{ - From: []*model.Item{from}, - To: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd", - Amount: 20000000000, - FeeRate: 1100, - } - resp, err := c.BuildDaoDepositTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) -} +// func TestBuildDaoDepositTransaction(t *testing.T) { +// from, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk") +// checkError(t, err) +// payload := &model.DaoDepositPayload{ +// From: []*model.Item{from}, +// To: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd", +// Amount: 20000000000, +// FeeRate: 1100, +// } +// resp, err := c.BuildDaoDepositTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// } -func TestBuildDaoWithdrawTransaction(t *testing.T) { - from, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk") - checkError(t, err) - payload := &model.DaoWithdrawPayload{ - From: []*model.Item{from}, - FeeRate: 1100, - } - resp, err := c.BuildDaoWithdrawTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) -} +// func TestBuildDaoWithdrawTransaction(t *testing.T) { +// from, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk") +// checkError(t, err) +// payload := &model.DaoWithdrawPayload{ +// From: []*model.Item{from}, +// FeeRate: 1100, +// } +// resp, err := c.BuildDaoWithdrawTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// } -func TestBuildDaoClaimTransaction(t *testing.T) { - from, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk") - checkError(t, err) - payload := &model.DaoClaimPayload{ - From: []*model.Item{from}, - FeeRate: 1100, - } - resp, err := c.BuildDaoClaimTransaction(payload) - checkError(t, err) - assert.NotNil(t, resp.TxView) - assert.NotNil(t, resp.ScriptGroups) -} +// func TestBuildDaoClaimTransaction(t *testing.T) { +// from, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk") +// checkError(t, err) +// payload := &model.DaoClaimPayload{ +// From: []*model.Item{from}, +// FeeRate: 1100, +// } +// resp, err := c.BuildDaoClaimTransaction(payload) +// checkError(t, err) +// assert.NotNil(t, resp.TxView) +// assert.NotNil(t, resp.ScriptGroups) +// } -func TestGetAccountInfo(t *testing.T) { - item, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq06y24q4tc4tfkgze35cc23yprtpzfrzygljdjh9") - checkError(t, err) - payload := &model.GetAccountInfoPayload{ - Item: item, - AssetInfo: model.NewUdtAsset(types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd")), - } - resp, err := c.GetAccountInfo(payload) - checkError(t, err) - // asset not nil - assert.NotEqual(t, "", resp.AccountAddress) - assert.NotEqual(t, "", resp.AccountType) -} +// func TestGetAccountInfo(t *testing.T) { +// item, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq06y24q4tc4tfkgze35cc23yprtpzfrzygljdjh9") +// checkError(t, err) +// payload := &model.GetAccountInfoPayload{ +// Item: item, +// AssetInfo: model.NewUdtAsset(types.HexToHash("0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd")), +// } +// resp, err := c.GetAccountInfo(payload) +// checkError(t, err) +// // asset not nil +// assert.NotEqual(t, "", resp.AccountAddress) +// assert.NotEqual(t, "", resp.AccountType) +// } -func TestGetSpentTransactionWithTransactionView(t *testing.T) { - payload := &model.GetSpentTransactionPayload{ - OutPoint: types.OutPoint{ - TxHash: types.HexToHash("0xb2e952a30656b68044e1d5eed69f1967347248967785449260e3942443cbeece"), - Index: 1, - }, - } - resp, err := c.GetSpentTransactionWithTransactionView(payload) - checkError(t, err) - assert.NotNil(t, resp.Value.Transaction) - assert.Equal(t, types.HexToHash("0x407033c3baa6104c9f46d3c7948b812274556148d74b0db251f50fc6e7507233"), *resp.Value.TxStatus.BlockHash) - assert.Equal(t, types.TransactionStatusCommitted, resp.Value.TxStatus.Status) - assert.Equal(t, uint64(0x17bc67c4078), *resp.Value.TxStatus.Timestamp) -} +// func TestGetSpentTransactionWithTransactionView(t *testing.T) { +// payload := &model.GetSpentTransactionPayload{ +// OutPoint: types.OutPoint{ +// TxHash: types.HexToHash("0xb2e952a30656b68044e1d5eed69f1967347248967785449260e3942443cbeece"), +// Index: 1, +// }, +// } +// resp, err := c.GetSpentTransactionWithTransactionView(payload) +// checkError(t, err) +// assert.NotNil(t, resp.Value.Transaction) +// assert.Equal(t, types.HexToHash("0x407033c3baa6104c9f46d3c7948b812274556148d74b0db251f50fc6e7507233"), *resp.Value.TxStatus.BlockHash) +// assert.Equal(t, types.TransactionStatusCommitted, resp.Value.TxStatus.Status) +// assert.Equal(t, uint64(0x17bc67c4078), *resp.Value.TxStatus.Timestamp) +// } -func TestGetSpentTransactionWithTransactionInfo(t *testing.T) { - payload := &model.GetSpentTransactionPayload{ - OutPoint: types.OutPoint{ - TxHash: types.HexToHash("0xb2e952a30656b68044e1d5eed69f1967347248967785449260e3942443cbeece"), - Index: 1, - }, - } - resp, err := c.GetSpentTransactionWithTransactionInfo(payload) - checkError(t, err) - assert.Equal(t, types.HexToHash("0x2c4e242e034e70a7b8ae5f899686c256dad2a816cc36ddfe2c1460cbbbbaaaed"), resp.Value.TxHash) - assert.Equal(t, 3, len(resp.Value.Records)) - assert.Equal(t, big.NewInt(0xd9ac33e984), resp.Value.Records[0].Amount) - assert.Equal(t, uint64(0x2877b6), resp.Value.Records[0].BlockNumber) - assert.Equal(t, uint64(0x70804bf000af6), resp.Value.Records[0].EpochNumber) - assert.Equal(t, 3, len(resp.Value.Records)) - assert.Equal(t, uint64(0x1f5), resp.Value.Fee) - assert.Equal(t, uint64(0x17bc67c4078), resp.Value.Timestamp) -} +// func TestGetSpentTransactionWithTransactionInfo(t *testing.T) { +// payload := &model.GetSpentTransactionPayload{ +// OutPoint: types.OutPoint{ +// TxHash: types.HexToHash("0xb2e952a30656b68044e1d5eed69f1967347248967785449260e3942443cbeece"), +// Index: 1, +// }, +// } +// resp, err := c.GetSpentTransactionWithTransactionInfo(payload) +// checkError(t, err) +// assert.Equal(t, types.HexToHash("0x2c4e242e034e70a7b8ae5f899686c256dad2a816cc36ddfe2c1460cbbbbaaaed"), resp.Value.TxHash) +// assert.Equal(t, 3, len(resp.Value.Records)) +// assert.Equal(t, big.NewInt(0xd9ac33e984), resp.Value.Records[0].Amount) +// assert.Equal(t, uint64(0x2877b6), resp.Value.Records[0].BlockNumber) +// assert.Equal(t, uint64(0x70804bf000af6), resp.Value.Records[0].EpochNumber) +// assert.Equal(t, 3, len(resp.Value.Records)) +// assert.Equal(t, uint64(0x1f5), resp.Value.Fee) +// assert.Equal(t, uint64(0x17bc67c4078), resp.Value.Timestamp) +// } -func TestQueryTransactions(t *testing.T) { - item, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv") - checkError(t, err) - payload := &model.QueryTransactionsPayload{ - Item: item, - AssetInfos: []*model.AssetInfo{model.NewCkbAsset()}, - BlockRange: &model.BlockRange{ - From: 2778100, - To: 3636218, - }, - Pagination: &model.PaginationRequest{ - Order: model.OrderAsc, - Limit: 2, - ReturnCount: true, - }, - } - resp1, err := c.QueryTransactionsWithTransactionView(payload) - checkError(t, err) - assert.NotNil(t, uint64(0x02), resp1.Count) - assert.NotNil(t, 2, len(resp1.Response)) - resp2, err := c.QueryTransactionsWithTransactionInfo(payload) - checkError(t, err) - assert.NotNil(t, uint64(0x02), resp2.Count) - assert.NotNil(t, 2, len(resp2.Response)) -} +// func TestQueryTransactions(t *testing.T) { +// item, err := model.NewAddressItem("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv") +// checkError(t, err) +// payload := &model.QueryTransactionsPayload{ +// Item: item, +// AssetInfos: []*model.AssetInfo{model.NewCkbAsset()}, +// BlockRange: &model.BlockRange{ +// From: 2778100, +// To: 3636218, +// }, +// Pagination: &model.PaginationRequest{ +// Order: model.OrderAsc, +// Limit: 2, +// ReturnCount: true, +// }, +// } +// resp1, err := c.QueryTransactionsWithTransactionView(payload) +// checkError(t, err) +// assert.NotNil(t, uint64(0x02), resp1.Count) +// assert.NotNil(t, 2, len(resp1.Response)) +// resp2, err := c.QueryTransactionsWithTransactionInfo(payload) +// checkError(t, err) +// assert.NotNil(t, uint64(0x02), resp2.Count) +// assert.NotNil(t, 2, len(resp2.Response)) +// } -func TestQueryTransactionsWithPage(t *testing.T) { - item, err := model.NewIdentityItemByPublicKeyHash("0x1a4ff63598e43af9cd42324abb7657fa849c5bc3") - checkError(t, err) - payload := &model.QueryTransactionsPayload{ - Item: item, - AssetInfos: []*model.AssetInfo{}, - Pagination: &model.PaginationRequest{ - Order: model.OrderDesc, - Limit: 1, - ReturnCount: true, - }, - } - resp, err := c.QueryTransactionsWithTransactionView(payload) - checkError(t, err) - assert.Equal(t, 1, len(resp.Response)) +// func TestQueryTransactionsWithPage(t *testing.T) { +// item, err := model.NewIdentityItemByPublicKeyHash("0x1a4ff63598e43af9cd42324abb7657fa849c5bc3") +// checkError(t, err) +// payload := &model.QueryTransactionsPayload{ +// Item: item, +// AssetInfos: []*model.AssetInfo{}, +// Pagination: &model.PaginationRequest{ +// Order: model.OrderDesc, +// Limit: 1, +// ReturnCount: true, +// }, +// } +// resp, err := c.QueryTransactionsWithTransactionView(payload) +// checkError(t, err) +// assert.Equal(t, 1, len(resp.Response)) - payload = &model.QueryTransactionsPayload{ - Item: item, - AssetInfos: []*model.AssetInfo{}, - Pagination: &model.PaginationRequest{ - Cursor: *resp.NextCursor, - Order: model.OrderDesc, - Limit: 2, - ReturnCount: true, - }, - } - resp, err = c.QueryTransactionsWithTransactionView(payload) - checkError(t, err) - assert.Equal(t, 2, len(resp.Response)) - assert.NotEqual(t, types.Hash{}, resp.Response[0].Value.Transaction.Hash) -} +// payload = &model.QueryTransactionsPayload{ +// Item: item, +// AssetInfos: []*model.AssetInfo{}, +// Pagination: &model.PaginationRequest{ +// Cursor: *resp.NextCursor, +// Order: model.OrderDesc, +// Limit: 2, +// ReturnCount: true, +// }, +// } +// resp, err = c.QueryTransactionsWithTransactionView(payload) +// checkError(t, err) +// assert.Equal(t, 2, len(resp.Response)) +// assert.NotEqual(t, types.Hash{}, resp.Response[0].Value.Transaction.Hash) +// } -func TestGetTransactionInfo(t *testing.T) { - resp, err := c.GetTransactionInfo(types.HexToHash("0x4329e4c751c95384a51072d4cbc9911a101fd08fc32c687353d016bf38b8b22c")) - checkError(t, err) - assert.NotNil(t, resp.Transaction) - assert.Equal(t, types.HexToHash("0x4329e4c751c95384a51072d4cbc9911a101fd08fc32c687353d016bf38b8b22c"), resp.Transaction.TxHash) - assert.Equal(t, types.TransactionStatusCommitted, resp.Status) -} +// func TestGetTransactionInfo(t *testing.T) { +// resp, err := c.GetTransactionInfo(types.HexToHash("0x4329e4c751c95384a51072d4cbc9911a101fd08fc32c687353d016bf38b8b22c")) +// checkError(t, err) +// assert.NotNil(t, resp.Transaction) +// assert.Equal(t, types.HexToHash("0x4329e4c751c95384a51072d4cbc9911a101fd08fc32c687353d016bf38b8b22c"), resp.Transaction.TxHash) +// assert.Equal(t, types.TransactionStatusCommitted, resp.Status) +// } -func TestGetBlockInfoByNumber(t *testing.T) { - payload := &model.GetBlockInfoPayload{ - BlockNumber: 2172093, - } - resp, err := c.GetBlockInfo(payload) - checkError(t, err) - assert.NotNil(t, resp) - assert.NotEqual(t, types.Hash{}, resp.ParentHash) - assert.NotEqual(t, types.Hash{}, resp.BlockHash) - assert.Equal(t, 3, len(resp.Transactions)) -} +// func TestGetBlockInfoByNumber(t *testing.T) { +// payload := &model.GetBlockInfoPayload{ +// BlockNumber: 2172093, +// } +// resp, err := c.GetBlockInfo(payload) +// checkError(t, err) +// assert.NotNil(t, resp) +// assert.NotEqual(t, types.Hash{}, resp.ParentHash) +// assert.NotEqual(t, types.Hash{}, resp.BlockHash) +// assert.Equal(t, 3, len(resp.Transactions)) +// } -func TestGetBlockInfoByHash(t *testing.T) { - payload := &model.GetBlockInfoPayload{ - BlockHash: types.HexToHash("0xee8adba356105149cb9dc1cb0d09430a6bd01182868787ace587961c0d64e742"), - } - resp, err := c.GetBlockInfo(payload) - checkError(t, err) - assert.NotNil(t, resp) - assert.NotEqual(t, types.Hash{}, resp.ParentHash) - assert.NotEqual(t, types.Hash{}, resp.BlockHash) - assert.Equal(t, 3, len(resp.Transactions)) -} +// func TestGetBlockInfoByHash(t *testing.T) { +// payload := &model.GetBlockInfoPayload{ +// BlockHash: types.HexToHash("0xee8adba356105149cb9dc1cb0d09430a6bd01182868787ace587961c0d64e742"), +// } +// resp, err := c.GetBlockInfo(payload) +// checkError(t, err) +// assert.NotNil(t, resp) +// assert.NotEqual(t, types.Hash{}, resp.ParentHash) +// assert.NotEqual(t, types.Hash{}, resp.BlockHash) +// assert.Equal(t, 3, len(resp.Transactions)) +// } -func TestGetDbInfo(t *testing.T) { - resp, err := c.GetDbInfo() - checkError(t, err) - assert.NotEqual(t, "", resp.Version) - assert.NotEqual(t, 0, resp.ConnSize) -} +// func TestGetDbInfo(t *testing.T) { +// resp, err := c.GetDbInfo() +// checkError(t, err) +// assert.NotEqual(t, "", resp.Version) +// assert.NotEqual(t, 0, resp.ConnSize) +// } -func TestMercuryInfo(t *testing.T) { - resp, err := c.GetMercuryInfo() - checkError(t, err) - assert.NotEqual(t, "", resp.MercuryVersion) - assert.NotEqual(t, "", resp.CkbNodeVersion) - assert.NotEqual(t, "", resp.NetworkType) -} +// func TestMercuryInfo(t *testing.T) { +// resp, err := c.GetMercuryInfo() +// checkError(t, err) +// assert.NotEqual(t, "", resp.MercuryVersion) +// assert.NotEqual(t, "", resp.CkbNodeVersion) +// assert.NotEqual(t, "", resp.NetworkType) +// } -func TestSyncStateInfo(t *testing.T) { - resp, err := c.GetSyncState() - checkError(t, err) - assert.NotEqual(t, "", resp.State) -} -func TestRegisterAddresses(t *testing.T) { - resp, err := c.RegisterAddresses([]string{ - "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vqdrhpvcu82numz73852ed45cdxn4kcn72cvxh4jt", - }) - checkError(t, err) - assert.True(t, len(resp) >= 1) -} +// func TestSyncStateInfo(t *testing.T) { +// resp, err := c.GetSyncState() +// checkError(t, err) +// assert.NotEqual(t, "", resp.State) +// } +// func TestRegisterAddresses(t *testing.T) { +// resp, err := c.RegisterAddresses([]string{ +// "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vqdrhpvcu82numz73852ed45cdxn4kcn72cvxh4jt", +// }) +// checkError(t, err) +// assert.True(t, len(resp) >= 1) +// } -func checkError(t *testing.T, err error) { - if err != nil { - t.Error(err, string(debug.Stack())) - } -} +// func checkError(t *testing.T, err error) { +// if err != nil { +// t.Error(err, string(debug.Stack())) +// } +// } diff --git a/rpc/client.go b/rpc/client.go index be721eb5..d565c881 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -152,6 +152,9 @@ type Client interface { // SendTransaction send new transaction into transaction pool. SendTransaction(ctx context.Context, tx *types.Transaction) (*types.Hash, error) + // SendTestTransaction send new transaction into transaction pool. + SendTestTransaction(ctx context.Context, tx *types.Transaction) (*types.Hash, error) + /// Test if a transaction can be accepted by the transaction pool without inserting it into the pool or rebroadcasting it to peers. /// The parameters and errors of this method are the same as `send_transaction`. TestTxPoolAccept(ctx context.Context, tx *types.Transaction) (*types.EntryCompleted, error) @@ -167,6 +170,9 @@ type Client interface { // ClearTxPool Removes all transactions from the transaction pool. ClearTxPool(ctx context.Context) error + // Removes all transactions from the verification queue. + ClearTxVerifyQueue(ctx context.Context) error + ////// Stats // GetBlockchainInfo return state info of blockchain GetBlockchainInfo(ctx context.Context) (*types.BlockchainInfo, error) @@ -685,6 +691,17 @@ func (cli *client) SendTransaction(ctx context.Context, tx *types.Transaction) ( return &result, err } +func (cli *client) SendTestTransaction(ctx context.Context, tx *types.Transaction) (*types.Hash, error) { + var result types.Hash + + err := cli.c.CallContext(ctx, &result, "send_test_transaction", *tx, "passthrough") + if err != nil { + return nil, err + } + + return &result, err +} + // TestTxPoolAccept(ctx context.Context, tx *types.Transaction) (*types.EntryCompleted, error) func (cli *client) TestTxPoolAccept(ctx context.Context, tx *types.Transaction) (*types.EntryCompleted, error) { var result types.EntryCompleted @@ -728,6 +745,10 @@ func (cli *client) ClearTxPool(ctx context.Context) error { return cli.c.CallContext(ctx, nil, "clear_tx_pool") } +func (cli *client) ClearTxVerifyQueue(ctx context.Context) error { + return cli.c.CallContext(ctx, nil, "clear_tx_verify_queue") +} + func (cli *client) GetBlockchainInfo(ctx context.Context) (*types.BlockchainInfo, error) { var result types.BlockchainInfo err := cli.c.CallContext(ctx, &result, "get_blockchain_info") diff --git a/types/chain.go b/types/chain.go index bc5b6967..c5e0612e 100644 --- a/types/chain.go +++ b/types/chain.go @@ -231,9 +231,11 @@ type CellWithStatus struct { } type TxStatus struct { - Status TransactionStatus `json:"status"` - BlockHash *Hash `json:"block_hash"` - Reason *string `json:"reason"` + Status TransactionStatus `json:"status"` + BlockHash *Hash `json:"block_hash"` + BlockNumber *uint64 `json:"block_number"` + TxIndex *uint `json:"tx_index"` + Reason *string `json:"reason"` } type TransactionWithStatus struct { diff --git a/types/common.go b/types/common.go index e943d3df..496eb34f 100644 --- a/types/common.go +++ b/types/common.go @@ -17,6 +17,7 @@ const ( NetworkMain Network = iota NetworkTest + NetworkPreview WitnessTypeLock WitnessType = iota WitnessTypeInputType diff --git a/types/json.go b/types/json.go index ec4df79f..7c421ae2 100644 --- a/types/json.go +++ b/types/json.go @@ -413,6 +413,10 @@ type jsonSyncState struct { FastTime hexutil.Uint64 `json:"fast_time"` LowTime hexutil.Uint64 `json:"low_time"` NormalTime hexutil.Uint64 `json:"normal_time"` + TipHash Hash `json:"tip_hash"` + TipNumber hexutil.Uint64 `json:"tip_number"` + UnverifiedTipHash Hash `json:"unverified_tip_hash"` + UnverifiedTipNumber hexutil.Uint64 `json:"unverified_tip_number"` } func (t *SyncState) UnmarshalJSON(input []byte) error { @@ -429,6 +433,10 @@ func (t *SyncState) UnmarshalJSON(input []byte) error { FastTime: uint64(jsonObj.FastTime), LowTime: uint64(jsonObj.LowTime), NormalTime: uint64(jsonObj.NormalTime), + TipHash: jsonObj.TipHash, + TipNumber: uint64(jsonObj.TipNumber), + UnverifiedTipHash: jsonObj.UnverifiedTipHash, + UnverifiedTipNumber: uint64(jsonObj.UnverifiedTipNumber), } return nil } @@ -756,6 +764,53 @@ func (r *FeeRateStatics) MarshalJSON() ([]byte, error) { return json.Marshal(jsonObj) } +type jsonTxStatus struct { + Status TransactionStatus `json:"status"` + BlockHash *Hash `json:"block_hash"` + BlockNumber *hexutil.Uint64 `json:"block_number"` + TxIndex *hexutil.Uint `json:"tx_index"` + Reason *string `json:"reason"` +} + +func (r *TxStatus) MarshalJSON() ([]byte, error) { + jsonObj := &jsonTxStatus{ + Status: r.Status, + BlockHash: r.BlockHash, + Reason: r.Reason, + } + + if r.BlockNumber != nil { + jsonObj.BlockNumber = (*hexutil.Uint64)(r.BlockNumber) + } + if r.TxIndex != nil { + jsonObj.TxIndex = (*hexutil.Uint)(r.TxIndex) + } + return json.Marshal(jsonObj) +} + +func (r *TxStatus) UnmarshalJSON(input []byte) error { + var result jsonTxStatus + if err := json.Unmarshal(input, &result); err != nil { + return err + } + + *r = TxStatus{ + Status: result.Status, + BlockHash: result.BlockHash, + Reason: result.Reason, + } + + if result.BlockNumber != nil { + r.BlockNumber = (*uint64)(result.BlockNumber) + } + + if result.TxIndex != nil { + r.TxIndex = (*uint)(result.TxIndex) + } + + return nil +} + type jsonTransactionWithStatus struct { Transaction *Transaction `json:"transaction"` Cycles *hexutil.Uint64 `json:"cycles"` diff --git a/types/json_test.go b/types/json_test.go index c59670f9..824fa4e2 100644 --- a/types/json_test.go +++ b/types/json_test.go @@ -158,6 +158,8 @@ func TestJsonTransactionWithStatus(t *testing.T) { "cycles": "0x16e04e", "time_added_to_pool": null, "tx_status": { + "block_number": "0x55e4b2", + "tx_index": "0x0", "block_hash": "0xe1ed2d2282aad742a95abe51c21d50b1c19e194f21fbd1ed2516f82bd042579a", "status": "committed", "reason": null @@ -177,6 +179,8 @@ func TestRejectedJsonTransactionWithStatus(t *testing.T) { "cycles": null, "time_added_to_pool": null, "tx_status": { + "block_number": "0x55e4b2", + "tx_index": "0x0", "block_hash": "0xe1ed2d2282aad742a95abe51c21d50b1c19e194f21fbd1ed2516f82bd042579a", "status": "rejected", "reason": "{\"type\":\"Resolve\",\"description\":\"Resolve failed Dead(OutPoint(0xb7c0dff4c715fe47950f5192fa275bbfe76735eeba0017b7da77d5cd6e6a501200000000))\"}" @@ -198,6 +202,8 @@ func TestUnknownJsonTransactionWithStatus(t *testing.T) { "cycles": null, "time_added_to_pool": null, "tx_status": { + "block_number": "0x55e4b2", + "tx_index": "0x0", "block_hash": "0x7b00ed399a69eb6b4191ce45e8337835bf3ecadabb8d7281de50fa07fb2034f1", "status": "unknown", "reason": null diff --git a/types/net.go b/types/net.go index b5ab6697..42536275 100644 --- a/types/net.go +++ b/types/net.go @@ -66,4 +66,8 @@ type SyncState struct { FastTime uint64 `json:"fast_time"` LowTime uint64 `json:"low_time"` NormalTime uint64 `json:"normal_time"` + TipHash Hash `json:"tip_hash"` + TipNumber uint64 `json:"tip_number"` + UnverifiedTipHash Hash `json:"unverified_tip_hash"` + UnverifiedTipNumber uint64 `json:"unverified_tip_number"` } diff --git a/types/pool.go b/types/pool.go index ba02cecf..494920e4 100644 --- a/types/pool.go +++ b/types/pool.go @@ -1,15 +1,19 @@ package types type TxPoolInfo struct { - TipHash Hash `json:"tip_hash"` - TipNumber uint64 `json:"tip_number"` + LastTxsUpdatedAt uint64 `json:"last_txs_updated_at"` + MaxTxPoolSize uint64 `json:"max_tx_pool_size"` + MinFeeRate uint64 `json:"min_fee_rate"` + MinRbfRate uint64 `json:"min_fee_rate"` + Orphan uint64 `json:"orphan"` Pending uint64 `json:"pending"` Proposed uint64 `json:"proposed"` - Orphan uint64 `json:"orphan"` - TotalTxSize uint64 `json:"total_tx_size"` + TipHash Hash `json:"tip_hash"` + TipNumber uint64 `json:"tip_number"` TotalTxCycles uint64 `json:"total_tx_cycles"` - MinFeeRate uint64 `json:"min_fee_rate"` - LastTxsUpdatedAt uint64 `json:"last_txs_updated_at"` + TotalTxSize uint64 `json:"total_tx_size"` + TxSizeLimit uint64 `json:"tx_size_limit"` + VerifyQueueSize uint64 `json:"verify_queue_size"` } type RawTxPool struct {