diff --git a/extras/jsonrpc/daemon.go b/extras/jsonrpc/daemon.go index 5d7516d..f3cafbb 100644 --- a/extras/jsonrpc/daemon.go +++ b/extras/jsonrpc/daemon.go @@ -140,11 +140,6 @@ func (d *Client) Commands() (*CommandsResponse, error) { return response, d.call(response, "commands", map[string]interface{}{}) } -func (d *Client) Status() (*StatusResponse, error) { - response := new(StatusResponse) - return response, d.call(response, "status", map[string]interface{}{}) -} - func (d *Client) WalletBalance() (*WalletBalanceResponse, error) { rawResponse, err := d.callNoDecode("wallet_balance", map[string]interface{}{}) if err != nil { @@ -165,11 +160,6 @@ func (d *Client) WalletList() (*WalletListResponse, error) { return response, d.call(response, "wallet_list", map[string]interface{}{}) } -func (d *Client) UTXOList() (*UTXOListResponse, error) { - response := new(UTXOListResponse) - return response, d.call(response, "utxo_list", map[string]interface{}{}) -} - func (d *Client) Version() (*VersionResponse, error) { response := new(VersionResponse) return response, d.call(response, "version", map[string]interface{}{}) @@ -184,13 +174,6 @@ func (d *Client) Get(url string, filename *string, timeout *uint) (*GetResponse, }) } -func (d *Client) ClaimList(name string) (*ClaimListResponse, error) { - response := new(ClaimListResponse) - return response, d.call(response, "claim_list", map[string]interface{}{ - "name": name, - }) -} - func (d *Client) ClaimShow(claimID *string, txid *string, nout *uint) (*ClaimShowResponse, error) { response := new(ClaimShowResponse) return response, d.call(response, "claim_show", map[string]interface{}{ @@ -330,14 +313,6 @@ func (d *Client) Resolve(url string) (*ResolveResponse, error) { }) } -func (d *Client) ChannelNew(name string, amount float64) (*ChannelNewResponse, error) { - response := new(ChannelNewResponse) - return response, d.call(response, "channel_new", map[string]interface{}{ - "channel_name": name, - "amount": amount, - }) -} - func (d *Client) BlobAnnounce(blobHash, sdHash, streamHash *string) (*BlobAnnounceResponse, error) { response := new(BlobAnnounceResponse) return response, d.call(response, "blob_announce", map[string]interface{}{ @@ -413,33 +388,6 @@ func (d *Client) NumClaimsInChannel(url string) (uint64, error) { return channel.ClaimsInChannel, nil } -func (d *Client) ClaimListMine() (*ClaimListMineResponse, error) { - response := new(ClaimListMineResponse) - err := d.call(response, "claim_list_mine", map[string]interface{}{}) - if err != nil { - return nil, err - } else if response == nil { - return nil, errors.Err("no response") - } - - return response, nil -} - -func (d *Client) ClaimAbandon(txID string, nOut int) (*ClaimAbandonResponse, error) { - response := new(ClaimAbandonResponse) - err := d.call(response, "claim_abandon", map[string]interface{}{ - "txid": txID, - "nout": nOut, - }) - if err != nil { - return nil, err - } else if response == nil { - return nil, errors.Err("no response") - } - - return response, nil -} - //============================================ // NEW SDK //============================================ @@ -522,3 +470,72 @@ func (d *Client) Publish(name, filePath string, bid float64, options PublishOpti structs.DefaultTagName = "json" return response, d.call(response, "publish", structs.Map(args)) } + +func (d *Client) ChannelNew(name string, amount float64, accountID *string) (*ChannelNewResponse, error) { + response := new(ChannelNewResponse) + return response, d.call(response, "channel_new", map[string]interface{}{ + "channel_name": name, + "amount": fmt.Sprintf("%.1f", amount), + "account_id": accountID, + }) +} + +func (d *Client) ClaimAbandon(txID string, nOut uint64, accountID *string, blocking bool) (*ClaimAbandonResponse, error) { + response := new(ClaimAbandonResponse) + err := d.call(response, "claim_abandon", map[string]interface{}{ + "txid": txID, + "nout": nOut, + "account_id": accountID, + }) + if err != nil { + return nil, err + } else if response == nil { + return nil, errors.Err("no response") + } + + return response, nil +} + +func (d *Client) AddressList(account *string) (*AddressListResponse, error) { + response := new(AddressListResponse) + return response, d.call(response, "address_list", map[string]interface{}{ + "account_id": account, + }) +} + +func (d *Client) ClaimList(name string) (*ClaimListResponse, error) { + response := new(ClaimListResponse) + return response, d.call(response, "claim_list", map[string]interface{}{ + "name": name, + }) +} + +func (d *Client) ClaimListMine(account *string, page uint64, pageSize uint64) (*ClaimListMineResponse, error) { + response := new(ClaimListMineResponse) + err := d.call(response, "claim_list_mine", map[string]interface{}{ + "account_id": account, + "page": page, + "page_size": pageSize, + }) + if err != nil { + return nil, err + } else if response == nil { + return nil, errors.Err("no response") + } + + return response, nil +} + +func (d *Client) Status() (*StatusResponse, error) { + response := new(StatusResponse) + return response, d.call(response, "status", map[string]interface{}{}) +} + +func (d *Client) UTXOList(account *string, page uint64, pageSize uint64) (*UTXOListResponse, error) { + response := new(UTXOListResponse) + return response, d.call(response, "utxo_list", map[string]interface{}{ + "account_id": account, + "page": page, + "page_size": pageSize, + }) +} diff --git a/extras/jsonrpc/daemon_test.go b/extras/jsonrpc/daemon_test.go index 86f0980..d8a57aa 100644 --- a/extras/jsonrpc/daemon_test.go +++ b/extras/jsonrpc/daemon_test.go @@ -4,9 +4,9 @@ import ( "fmt" "strconv" "testing" + "time" "github.com/lbryio/lbry.go/extras/util" - "github.com/shopspring/decimal" log "github.com/sirupsen/logrus" ) @@ -35,7 +35,7 @@ func TestClient_AccountFund(t *testing.T) { if err != nil { t.Error(err) } - account := (*accounts.LBCRegtest)[0].ID + account := (accounts.LBCRegtest)[0].ID balanceString, err := d.AccountBalance(&account) if err != nil { t.Error(err) @@ -76,7 +76,7 @@ func TestClient_Publish(t *testing.T) { t.Error(err) } address := string(*addressResponse) - got, err := d.Publish("test", "/home/niko/test.txt", 13.37, PublishOptions{ + got, err := d.Publish("test", "/home/niko/test.txt", 14.37, PublishOptions{ Metadata: &Metadata{ Fee: &Fee{ Currency: "LBC", @@ -95,7 +95,7 @@ func TestClient_Publish(t *testing.T) { Sources: nil, }, ChannelName: nil, - ChannelID: nil, + ChannelID: util.PtrToString("0a32af305113435d1cdf4ec61452b9a6dcb74da8"), ChannelAccountID: nil, AccountID: nil, ClaimAddress: &address, @@ -106,3 +106,73 @@ func TestClient_Publish(t *testing.T) { } log.Infof("%+v", *got) } + +func TestClient_ChannelNew(t *testing.T) { + d := NewClient("") + got, err := d.ChannelNew("@Test", 13.37, nil) + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} + +func TestClient_ClaimAbandon(t *testing.T) { + d := NewClient("") + channelResponse, err := d.ChannelNew("@TestToDelete", 13.37, nil) + if err != nil { + t.Error(err) + } + txID := channelResponse.Output.Txid + nout := channelResponse.Output.Nout + time.Sleep(10 * time.Second) + got, err := d.ClaimAbandon(txID, nout, nil, false) + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} + +func TestClient_AddressList(t *testing.T) { + d := NewClient("") + got, err := d.AddressList(nil) + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} + +func TestClient_ClaimList(t *testing.T) { + d := NewClient("") + got, err := d.ClaimList("test") + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} + +func TestClient_ClaimListMine(t *testing.T) { + d := NewClient("") + got, err := d.ClaimListMine(nil, 0, 50) + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} + +func TestClient_Status(t *testing.T) { + d := NewClient("") + got, err := d.Status() + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} + +func TestClient_UTXOList(t *testing.T) { + d := NewClient("") + got, err := d.UTXOList(nil, 0, 50) + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} diff --git a/extras/jsonrpc/daemon_types.go b/extras/jsonrpc/daemon_types.go index b3e9614..7c1af7b 100644 --- a/extras/jsonrpc/daemon_types.go +++ b/extras/jsonrpc/daemon_types.go @@ -24,41 +24,6 @@ type Fee struct { Address *string `json:"address"` } -type Support struct { - Amount decimal.Decimal `json:"amount"` - Nout int `json:"nout"` - Txid string `json:"txid"` -} - -type Claim struct { - Address string `json:"address"` - Amount decimal.Decimal `json:"amount"` - BlocksToExpiration int `json:"blocks_to_expiration"` - Category string `json:"category"` - ClaimID string `json:"claim_id"` - ClaimSequence int `json:"claim_sequence"` - Confirmations int `json:"confirmations"` - DecodedClaim bool `json:"decoded_claim"` - Depth int `json:"depth"` - EffectiveAmount decimal.Decimal `json:"effective_amount"` - ExpirationHeight int `json:"expiration_height"` - Expired bool `json:"expired"` - Height int `json:"height"` - Hex string `json:"hex"` - IsSpent bool `json:"is_spent"` - Name string `json:"name"` - Nout int `json:"nout"` - PermanentUrl string `json:"permanent_url"` - Supports []Support `json:"supports"` - Txid string `json:"txid"` - ValidAtHeight int `json:"valid_at_height"` - Value lbryschema.Claim `json:"value"` - Error *string `json:"error,omitempty"` - ChannelName *string `json:"channel_name,omitempty"` - HasSignature *bool `json:"has_signature,omitempty"` - SignatureIsValid *bool `json:"signature_is_valid,omitempty"` -} - type File struct { ClaimID string `json:"claim_id"` Completed bool `json:"completed"` @@ -191,62 +156,8 @@ type VersionResponse struct { Processor string `json:"processor"` PythonVersion string `json:"python_version"` } -type StatusResponse struct { - BlobManager struct { - FinishedBlobs int `json:"finished_blobs"` - } `json:"blob_manager"` - ConnectionStatus struct { - Code string `json:"code"` - Message string `json:"message"` - } `json:"connection_status"` - Dht struct { - NodeID string `json:"node_id"` - PeersInRoutingTable int `json:"peers_in_routing_table"` - } `json:"dht"` - FileManager struct { - ManagedFiles int `json:"managed_files"` - } `json:"file_manager"` - HashAnnouncer struct { - AnnounceQueueSize int `json:"announce_queue_size"` - } `json:"hash_announcer"` - InstallationID string `json:"installation_id"` - IsFirstRun bool `json:"is_first_run"` - IsRunning bool `json:"is_running"` - SkippedComponents []string `json:"skipped_components"` - StartupStatus struct { - BlobManager bool `json:"blob_manager"` - BlockchainHeaders bool `json:"blockchain_headers"` - Database bool `json:"database"` - Dht bool `json:"dht"` - ExchangeRateManager bool `json:"exchange_rate_manager"` - FileManager bool `json:"file_manager"` - HashAnnouncer bool `json:"hash_announcer"` - PaymentRateManager bool `json:"payment_rate_manager"` - PeerProtocolServer bool `json:"peer_protocol_server"` - RateLimiter bool `json:"rate_limiter"` - StreamIdentifier bool `json:"stream_identifier"` - Upnp bool `json:"upnp"` - Wallet bool `json:"wallet"` - } `json:"startup_status"` - Wallet struct { - BestBlockchain string `json:"best_blockchain"` - Blocks int `json:"blocks"` - BlocksBehind int `json:"blocks_behind"` - IsEncrypted bool `json:"is_encrypted"` - } `json:"wallet"` -} -type ClaimListResponse struct { - Claims []Claim `json:"claims"` - LastTakeoverHeight int `json:"last_takeover_height"` - SupportsWithoutClaims []Support `json:"supports_without_claims"` -} -type ClaimListMineResponse []Claim type ClaimShowResponse Claim -type ClaimAbandonResponse struct { - Txid string `json:"txid"` - Fee float64 `json:"fee"` -} type PeerListResponsePeer struct { IP string `json:"host"` @@ -303,39 +214,6 @@ type ResolveResponseItem struct { Error *string `json:"error,omitempty"` } -type ChannelNewResponse struct { - ClaimID string `json:"claim_id"` - Fee decimal.Decimal `json:"fee"` - Nout int `json:"nout"` - Success bool `json:"success"` - Tx string `json:"tx"` - Txid string `json:"txid"` -} - -type ChannelListSingleResponse struct { - Address string `json:"address"` - Amount decimal.Decimal `json:"amount"` - BlocksToExpiration int `json:"blocks_to_expiration"` - CanSign bool `json:"can_sign"` - Category string `json:"category"` - ClaimID string `json:"claim_id"` - Confirmations int `json:"confirmations"` - DecodedClaim bool `json:"decoded_claim"` - ExpirationHeight int `json:"expiration_height"` - Expired bool `json:"expired"` - HasSignature bool `json:"has_signature"` - Height int `json:"height"` - Hex string `json:"hex"` - IsPending bool `json:"is_pending"` - IsSpent bool `json:"is_spent"` - Name string `json:"name"` - Nout int `json:"nout"` - Txid string `json:"txid"` - Value *lbryschema.Claim `json:"value"` -} - -type ChannelListResponse []ChannelListSingleResponse - type WalletListResponse []string type BlobAnnounceResponse bool @@ -346,18 +224,6 @@ type WalletPrefillAddressesResponse struct { Hex string `json:"hex"` } -type UTXOListResponse []struct { - Address string `json:"address"` - Amount decimal.Decimal `json:"amount"` - Height int `json:"height"` - IsClaim bool `json:"is_claim"` - IsCoinbase bool `json:"is_coinbase"` - IsSupport bool `json:"is_support"` - IsUpdate bool `json:"is_update"` - Nout int `json:"nout"` - Txid string `json:"txid"` -} - type WalletNewAddressResponse string type WalletUnusedAddressResponse string @@ -393,9 +259,9 @@ type Account struct { } type AccountListResponse struct { - LBCMainnet *[]Account `json:"lbc_mainnet"` - LBCTestnet *[]Account `json:"lbc_testnet"` - LBCRegtest *[]Account `json:"lbc_regtest"` + LBCMainnet []Account `json:"lbc_mainnet"` + LBCTestnet []Account `json:"lbc_testnet"` + LBCRegtest []Account `json:"lbc_regtest"` } type AccountBalanceResponse string @@ -403,8 +269,8 @@ type Transaction struct { Address string `json:"address"` Amount string `json:"amount"` ClaimID string `json:"claim_id"` - Confirmations int64 `json:"confirmations"` - Height int64 `json:"height"` + Confirmations int `json:"confirmations"` + Height int `json:"height"` IsChange bool `json:"is_change"` IsMine bool `json:"is_mine"` Name string `json:"name"` @@ -415,8 +281,8 @@ type Transaction struct { Value *lbryschema.Claim `json:"value"` } -type AccountFundResponse struct { - Height int64 `json:"height"` +type TransactionSummary struct { + Height int `json:"height"` Hex string `json:"hex"` Inputs []Transaction `json:"inputs"` Outputs []Transaction `json:"outputs"` @@ -425,20 +291,140 @@ type AccountFundResponse struct { Txid string `json:"txid"` } -type AddressUnusedResponse string +type AccountFundResponse TransactionSummary + +type Address string +type AddressUnusedResponse Address +type AddressListResponse []Address type PublishResponse struct { - ClaimAddress string `json:"claim_address"` - ClaimID string `json:"claim_id"` - Output Transaction `json:"output"` - Success bool `json:"success"` - Tx struct { - Height int64 `json:"height"` - Hex string `json:"hex"` - Inputs []Transaction `json:"inputs"` - Outputs []Transaction `json:"inputs"` - } `json:"tx"` - TotalFee string `json:"total_fee"` - TotalOutput string `json:"total_output"` - Txid string `json:"txid"` + ClaimAddress string `json:"claim_address"` + ClaimID string `json:"claim_id"` + Output Transaction `json:"output"` + Success bool `json:"success"` + Tx TransactionSummary `json:"tx"` +} + +type ChannelNewResponse PublishResponse + +type ChannelListResponse struct { + Items []Transaction `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` +} + +type ClaimAbandonResponse struct { + Success bool `json:"success"` + Tx TransactionSummary `json:"tx"` +} +type Support struct { + Amount string `json:"amount"` + Nout uint64 `json:"nout"` + Txid string `json:"txid"` +} + +type Claim struct { + Address string `json:"address"` + Amount string `json:"amount"` + ChannelName *string `json:"channel_name,omitempty"` + ClaimID string `json:"claim_id"` + ClaimSequence uint64 `json:"claim_sequence"` + DecodedClaim bool `json:"decoded_claim"` + Depth int64 `json:"depth"` + EffectiveAmount string `json:"effective_amount"` + HasSignature *bool `json:"has_signature,omitempty"` + Height int `json:"height"` + Hex string `json:"hex"` + Name string `json:"name"` + Nout uint64 `json:"nout"` + PermanentUrl string `json:"permanent_url"` + SignatureIsValid *bool `json:"signature_is_valid,omitempty"` + Supports []Support `json:"supports"` + Txid string `json:"txid"` + ValidAtHeight int `json:"valid_at_height"` + Value lbryschema.Claim `json:"value"` +} + +type ClaimListResponse struct { + Claims []Claim `json:"claims"` + LastTakeoverHeight int `json:"last_takeover_height"` + SupportsWithoutClaims []Support `json:"supports_without_claims"` +} + +type ClaimListMineResponse struct { + Claims []Claim `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` +} + +type StatusResponse struct { + BlobManager struct { + FinishedBlobs uint64 `json:"finished_blobs"` + } `json:"blob_manager"` + ConnectionStatus struct { + Code string `json:"code"` + Message string `json:"message"` + } `json:"connection_status"` + Dht struct { + NodeID string `json:"node_id"` + PeersInRoutingTable uint64 `json:"peers_in_routing_table"` + } `json:"dht"` + FileManager struct { + ManagedFiles uint64 `json:"managed_files"` + } `json:"file_manager"` + HashAnnouncer struct { + AnnounceQueueSize uint64 `json:"announce_queue_size"` + } `json:"hash_announcer"` + InstallationID string `json:"installation_id"` + IsFirstRun bool `json:"is_first_run"` + IsRunning bool `json:"is_running"` + SkippedComponents []string `json:"skipped_components"` + StartupStatus struct { + BlobManager bool `json:"blob_manager"` + BlockchainHeaders bool `json:"blockchain_headers"` + Database bool `json:"database"` + Dht bool `json:"dht"` + ExchangeRateManager bool `json:"exchange_rate_manager"` + FileManager bool `json:"file_manager"` + HashAnnouncer bool `json:"hash_announcer"` + PaymentRateManager bool `json:"payment_rate_manager"` + PeerProtocolServer bool `json:"peer_protocol_server"` + RateLimiter bool `json:"rate_limiter"` + Upnp bool `json:"upnp"` + Wallet bool `json:"wallet"` + } `json:"startup_status"` + Upnp struct { + AioupnpVersion string `json:"aioupnp_version"` + DhtRedirectSet bool `json:"dht_redirect_set"` + ExternalIp string `json:"external_ip"` + Gateway string `json:"gateway"` + PeerRedirectSet bool `json:"peer_redirect_set"` + Redirects struct{} `json:"redirects"` + } + Wallet struct { + BestBlockchain string `json:"best_blockchain"` + Blocks int `json:"blocks"` + BlocksBehind int `json:"blocks_behind"` + IsEncrypted bool `json:"is_encrypted"` + IsLocked bool `json:"is_locked"` + } `json:"wallet"` +} + +type UTXOListResponse struct { + UTXOs []struct { + Address string `json:"address"` + Amount string `json:"amount"` + Height int `json:"height"` + IsClaim bool `json:"is_claim"` + IsCoinbase bool `json:"is_coinbase"` + IsSupport bool `json:"is_support"` + IsUpdate bool `json:"is_update"` + Nout int `json:"nout"` + Txid string `json:"txid"` + } `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` }