Skip to content

Commit

Permalink
Add support to v0.119.0
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Oct 27, 2024
1 parent a0b6e82 commit 6f4ab2e
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 12 deletions.
4 changes: 3 additions & 1 deletion crypto/bech32/bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion crypto/secp256k1/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 55 additions & 0 deletions types/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions types/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))\"}"
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions types/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
16 changes: 10 additions & 6 deletions types/pool.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 6f4ab2e

Please sign in to comment.