diff --git a/rpc/daemon/jsonrpc.go b/rpc/daemon/jsonrpc.go index 7ab2a10..51e80dd 100644 --- a/rpc/daemon/jsonrpc.go +++ b/rpc/daemon/jsonrpc.go @@ -6,30 +6,6 @@ import ( "fmt" ) -const ( - methodGenerateBlocks = "generateblocks" - methodGetAlternateChains = "get_alternate_chains" - methodGetBans = "get_bans" - methodGetBlock = "get_block" - methodGetBlockCount = "get_block_count" - methodGetBlockHeadersRange = "get_block_headers_range" - methodGetBlockHeaderByHash = "get_block_header_by_hash" - methodGetBlockHeaderByHeight = "get_block_header_by_height" - methodGetCoinbaseTxSum = "get_coinbase_tx_sum" - methodGetConnections = "get_connections" - methodGetFeeEstimate = "get_fee_estimate" - methodGetInfo = "get_info" - methodGetLastBlockHeader = "get_last_block_header" - methodGetVersion = "get_version" - methodHardForkInfo = "hard_fork_info" - methodOnGetBlockHash = "on_get_block_hash" - methodRPCAccessTracking = "rpc_access_tracking" - methodRelayTx = "relay_tx" - methodSetBans = "set_bans" - methodSyncInfo = "sync_info" - methodCalcPow = "calc_pow" -) - // GetAlternateChains displays alternative chains seen by the node. // // (restricted). @@ -38,7 +14,7 @@ func (c *Client) GetAlternateChains( ) (*GetAlternateChainsResult, error) { resp := &GetAlternateChainsResult{} - err := c.JSONRPC(ctx, methodGetAlternateChains, nil, resp) + err := c.JSONRPC(ctx, "get_alternate_chains", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -55,7 +31,7 @@ func (c *Client) RPCAccessTracking( ) (*RPCAccessTrackingResult, error) { resp := &RPCAccessTrackingResult{} - err := c.JSONRPC(ctx, methodRPCAccessTracking, nil, resp) + err := c.JSONRPC(ctx, "rpc_access_tracking", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -69,7 +45,7 @@ func (c *Client) HardForkInfo( ) (*HardForkInfoResult, error) { resp := &HardForkInfoResult{} - err := c.JSONRPC(ctx, methodHardForkInfo, nil, resp) + err := c.JSONRPC(ctx, "hard_fork_info", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -83,7 +59,7 @@ func (c *Client) HardForkInfo( func (c *Client) GetBans(ctx context.Context) (*GetBansResult, error) { resp := &GetBansResult{} - err := c.JSONRPC(ctx, methodGetBans, nil, resp) + err := c.JSONRPC(ctx, "get_bans", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -109,7 +85,7 @@ func (c *Client) SetBans( ) (*SetBansResult, error) { resp := &SetBansResult{} - err := c.JSONRPC(ctx, methodSetBans, params, resp) + err := c.JSONRPC(ctx, "set_bans", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -123,7 +99,7 @@ func (c *Client) SetBans( func (c *Client) GetVersion(ctx context.Context) (*GetVersionResult, error) { resp := &GetVersionResult{} - err := c.JSONRPC(ctx, methodGetVersion, nil, resp) + err := c.JSONRPC(ctx, "get_version", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -135,20 +111,16 @@ func (c *Client) GetVersion(ctx context.Context) (*GetVersionResult, error) { // GenerateBlocks RPC method. type GenerateBlocksRequestParameters struct { // AmountOfBlocks is the number of blocks to be generated. - // AmountOfBlocks uint64 `json:"amount_of_blocks,omitempty"` // WalletAddress is the address of the wallet that will get the rewards // of the coinbase transaction for such the blocks generates. - // WalletAddress string `json:"wallet_address,omitempty"` // PreviousBlock TODO - // PreviousBlock string `json:"prev_block,omitempty"` // StartingNonce TODO - // StartingNonce uint32 `json:"starting_nonce,omitempty"` } @@ -163,7 +135,7 @@ func (c *Client) GenerateBlocks( ) (*GenerateBlocksResult, error) { resp := &GenerateBlocksResult{} - err := c.JSONRPC(ctx, methodGenerateBlocks, params, resp) + err := c.JSONRPC(ctx, "generateblocks", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -176,7 +148,7 @@ func (c *Client) GetBlockCount( ) (*GetBlockCountResult, error) { resp := &GetBlockCountResult{} - err := c.JSONRPC(ctx, methodGetBlockCount, nil, resp) + err := c.JSONRPC(ctx, "get_block_count", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -190,7 +162,7 @@ func (c *Client) OnGetBlockHash( resp := "" params := []uint64{height} - err := c.JSONRPC(ctx, methodOnGetBlockHash, params, &resp) + err := c.JSONRPC(ctx, "on_get_block_hash", params, &resp) if err != nil { return "", fmt.Errorf("jsonrpc: %w", err) } @@ -206,7 +178,7 @@ func (c *Client) RelayTx( "txids": txns, } - err := c.JSONRPC(ctx, methodRelayTx, params, resp) + err := c.JSONRPC(ctx, "relay_tx", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -231,7 +203,7 @@ func (c *Client) GetConnections( ) (*GetConnectionsResult, error) { resp := &GetConnectionsResult{} - err := c.JSONRPC(ctx, methodGetConnections, nil, resp) + err := c.JSONRPC(ctx, "get_connections", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -244,7 +216,7 @@ func (c *Client) GetConnections( func (c *Client) GetInfo(ctx context.Context) (*GetInfoResult, error) { resp := &GetInfoResult{} - if err := c.JSONRPC(ctx, methodGetInfo, nil, resp); err != nil { + if err := c.JSONRPC(ctx, "get_info", nil, resp); err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -256,7 +228,7 @@ func (c *Client) GetLastBlockHeader( ) (*GetLastBlockHeaderResult, error) { resp := &GetLastBlockHeaderResult{} - err := c.JSONRPC(ctx, methodGetLastBlockHeader, nil, resp) + err := c.JSONRPC(ctx, "get_last_block_header", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -273,7 +245,7 @@ func (c *Client) GetCoinbaseTxSum( "count": count, } - err := c.JSONRPC(ctx, methodGetCoinbaseTxSum, params, resp) + err := c.JSONRPC(ctx, "get_coinbase_tx_sum", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -298,7 +270,7 @@ func (c *Client) GetBlockHeadersRange( ) (*GetBlockHeadersRangeResult, error) { resp := &GetBlockHeadersRangeResult{} - err := c.JSONRPC(ctx, methodGetBlockHeadersRange, params, resp) + err := c.JSONRPC(ctx, "get_block_headers_range", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -316,7 +288,7 @@ func (c *Client) GetBlockHeaderByHeight( "height": height, } - err := c.JSONRPC(ctx, methodGetBlockHeaderByHeight, params, resp) + err := c.JSONRPC(ctx, "get_block_header_by_height", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -334,7 +306,7 @@ func (c *Client) GetBlockHeaderByHash( "hashes": hashes, } - err := c.JSONRPC(ctx, methodGetBlockHeaderByHash, params, resp) + err := c.JSONRPC(ctx, "get_block_header_by_hash", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -349,7 +321,7 @@ func (c *Client) GetBlock( ) (*GetBlockResult, error) { resp := &GetBlockResult{} - err := c.JSONRPC(ctx, methodGetBlock, params, resp) + err := c.JSONRPC(ctx, "get_block", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -363,7 +335,7 @@ func (c *Client) GetFeeEstimate(ctx context.Context, graceBlocks uint64) (*GetFe "grace_blocks": graceBlocks, } - err := c.JSONRPC(ctx, methodGetFeeEstimate, params, resp) + err := c.JSONRPC(ctx, "get_fee_estimate", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -374,7 +346,7 @@ func (c *Client) GetFeeEstimate(ctx context.Context, graceBlocks uint64) (*GetFe func (c *Client) SyncInfo(ctx context.Context) (*SyncInfoResult, error) { resp := &SyncInfoResult{} - err := c.JSONRPC(ctx, methodSyncInfo, nil, resp) + err := c.JSONRPC(ctx, "sync_info", nil, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -385,7 +357,7 @@ func (c *Client) SyncInfo(ctx context.Context) (*SyncInfoResult, error) { func (c *Client) CalcPow(ctx context.Context, params CalcPowParameters) (string, error) { var resp string - err := c.JSONRPC(ctx, methodCalcPow, params, &resp) + err := c.JSONRPC(ctx, "calc_pow", params, &resp) if err != nil { return "", fmt.Errorf("jsonrpc: %w", err) } diff --git a/rpc/daemon/types.go b/rpc/daemon/types.go index b4257ce..984b467 100644 --- a/rpc/daemon/types.go +++ b/rpc/daemon/types.go @@ -4,23 +4,19 @@ package daemon // will contain. type RPCResultFooter struct { // Status dictates whether the request worked or not. "OK" means good. - // Status string `json:"status"` // States if the result is obtained using the bootstrap mode, and is // therefore not trusted (`true`), or when the daemon is fully synced // and thus handles the RPC locally (`false`). - // Untrusted bool `json:"untrusted"` // Credits indicates the number of credits available to the requesting // client, if payment for RPC is enabled, otherwise, 0. - // Credits uint64 `json:"credits,omitempty"` // TopHash is the hash of the highest block in the chain, If payment // for RPC is enabled, otherwise, empty. - // TopHash string `json:"top_hash,omitempty"` } @@ -28,44 +24,37 @@ type RPCResultFooter struct { // RPC method. type GetAlternateChainsResult struct { // Chains is the array of alternate chains seen by the node. - // Chains []struct { // BlockHash is the hash of the first diverging block of this // alternative chain. - // BlockHash string `json:"block_hash"` - // BlockHashes TODO - // + // BlockHashes is a slice of all the block hashes in the altchain + // that are not in the main chain BlockHashes []string `json:"block_hashes"` // Difficulty is the cumulative difficulty of all blocks in the // alternative chain. - // Difficulty int64 `json:"difficulty"` // DifficultyTop64 is the most-significant 64 bits of the // 128-bit network difficulty. - // DifficultyTop64 int `json:"difficulty_top64"` // Height is the block height of the first diverging block of // this alternative chain. - // Height uint64 `json:"height"` // Length is the length in blocks of this alternative chain, // after divergence. - // Length uint64 `json:"length"` - // MainChainParentBlock TODO - // + // MainChainParentBlock is the hash of the greatest height block + // that is shared between the alternative chain and the main chain. MainChainParentBlock string `json:"main_chain_parent_block"` // WideDifficulty is the network difficulty as a hexadecimal // string representing a 128-bit number. - // WideDifficulty string `json:"wide_difficulty"` } `json:"chains"` @@ -78,21 +67,17 @@ type RPCAccessTrackingResult struct { Data []struct { // Count is the number of times that the monero daemon received // a request for this RPC method. - // Count uint64 `json:"count"` // RPC is the name of the remote procedure call. - // RPC string `json:"rpc"` // Time indicates how much time the daemon spent serving this // procedure. - // Time uint64 `json:"time"` // Credits indicates the number of credits consumed for this // method. - // Credits uint64 `json:"credits"` } `json:"data"` @@ -102,40 +87,31 @@ type RPCAccessTrackingResult struct { // HardForkInfoResult is the result of a call to the HardForkInfo RPC method. type HardForkInfoResult struct { // EarliestHeight is the earliest height at which is allowed. - // EarliestHeight int `json:"earliest_height"` // Whether of not the hard fork is enforced. - // Enabled bool `json:"enabled"` // State indicates the current hard fork state: - // // 0 - likely forked // 1 - update needed // 2 - ready - // State int `json:"state"` // The number of votes required to enable . - // Threshold int `json:"threshold"` // Version () corresponds to the major block version for the // fork. - // Version int `json:"version"` // Votes is the number of votes to enable - // Votes int `json:"votes"` // Voting indicates which version this node is voting for/using. - // Voting int `json:"voting"` // Window is the size of the voting window. - // Window int `json:"window"` RPCResultFooter `json:",inline"` @@ -152,20 +128,16 @@ type GetVersionResult struct { // GetBansResult is the result of a call to the GetBans RPC method. type GetBansResult struct { // Bans contains the list of nodes banned by this node. - // Bans []struct { // Host is the string representation of the node that is // banned. - // Host string `json:"host"` // IP is the integer representation of the host banned. - // IP int `json:"ip"` // Seconds represents how many seconds are left for the ban to // be lifted. - // Seconds uint `json:"seconds"` } `json:"bans"` @@ -181,12 +153,10 @@ type SetBansResult struct { // method. type GetFeeEstimateResult struct { // Fee is the per kB fee estimate. - // Fee int `json:"fee"` // QuantizationMask indicates that the fee should be rounded up to an // even multiple of this value. - // QuantizationMask int `json:"quantization_mask"` RPCResultFooter `json:",inline"` @@ -250,21 +220,20 @@ type GetBlockTemplateParams struct { // method. type GetBlockTemplateResult struct { // BlockhashingBlob is the blob on which to try to find a valid nonce. - // BlockhashingBlob string `json:"blockhashing_blob"` // BlocktemplateBlob is the blob on which to try to mine a new block. BlocktemplateBlob string `json:"blocktemplate_blob"` // Difficulty is the difficulty of the next block. - Difficulty int64 `json:"difficulty"` + Difficulty uint64 `json:"difficulty"` // ExpectedReward is the coinbase reward expected to be received if the // block is successfully mined. - ExpectedReward int64 `json:"expected_reward"` + ExpectedReward uint64 `json:"expected_reward"` // Height is the height on which to mine. - Height int `json:"height"` + Height uint64 `json:"height"` // PrevHash is the hash of the most recent block on which to mine the // next block. @@ -272,7 +241,7 @@ type GetBlockTemplateResult struct { // ReservedOffset is the offset of the reserved data on the block // template blob, in bytes. - ReservedOffset int `json:"reserved_offset"` + ReservedOffset uint `json:"reserved_offset"` // SeedHash is the hash of block to use as seed for RandomX SeedHash string `json:"seed_hash"` @@ -401,10 +370,10 @@ type RelayTxResult struct { // GetCoinbaseTxSumResult is the result of a call to the GetCoinbaseTxSum RPC // method. type GetCoinbaseTxSumResult struct { - EmissionAmount int64 `json:"emission_amount"` - EmissionAmountTop64 int `json:"emission_amount_top64"` - FeeAmount int `json:"fee_amount"` - FeeAmountTop64 int `json:"fee_amount_top64"` + EmissionAmount uint64 `json:"emission_amount"` + EmissionAmountTop64 uint64 `json:"emission_amount_top64"` + FeeAmount uint64 `json:"fee_amount"` + FeeAmountTop64 uint64 `json:"fee_amount_top64"` WideEmissionAmount string `json:"wide_emission_amount"` WideFeeAmount string `json:"wide_fee_amount"` @@ -413,108 +382,84 @@ type GetCoinbaseTxSumResult struct { type BlockHeader struct { // BlockSize is the block size in bytes. - // BlockSize uint64 `json:"block_size"` - // BlockWeight TODO - // + // BlockWeight is the adjusted block size, in bytes. + // This is the raw size, plus a positive adjustment for any Bulletproof transactions with more than 2 outputs. BlockWeight uint64 `json:"block_weight"` // CumulativeDifficulty is the cumulative difficulty of all // blocks up to this one. - // CumulativeDifficulty uint64 `json:"cumulative_difficulty"` // CumulativeDifficultyTop64 most significant 64 bits of the // 128-bit cumulative difficulty. - // CumulativeDifficultyTop64 uint64 `json:"cumulative_difficulty_top64"` // Depth is the number of blocks succeeding this block on the // blockchain. (the larger this number, the oldest this block // is). - // Depth uint64 `json:"depth"` // Difficulty is the difficulty that was set for mining this block. - // Difficulty uint64 `json:"difficulty"` // DifficultyTop64 corresponds to the most significant 64-bit of // the 128-bit difficulty. - // DifficultyTop64 uint64 `json:"difficulty_top64"` // Hash is the hash of this block. - // Hash string `json:"hash"` // Height is the number of blocks preceding this block on the // blockchain. - // Height uint64 `json:"height"` - // LongTermWeight TODO - // + // LongTermWeight is the long term block weight, based on the median weight of the preceding 100000 blocks. LongTermWeight uint64 `json:"long_term_weight"` // MajorVersion is the major version of the monero protocol at // this block height. - // MajorVersion uint `json:"major_version"` - // MinerTxHash TODO - // + // MinerTxHash is the hash of this block's coinbase transaction. MinerTxHash string `json:"miner_tx_hash"` // MinorVersion is the minor version of the monero protocol at // this block height. - // MinorVersion uint `json:"minor_version"` - // Nonce is the cryptographic random one-time number used in - // mining this block. - // - Nonce uint64 `json:"nonce"` + // Nonce is the number used to mine this block. + Nonce uint32 `json:"nonce"` // NumTxes is the number of transactions in this block, not // counting the coinbase tx. - // NumTxes uint `json:"num_txes"` // OrphanStatus indicates whether this block is part of the // longest chain or not (true == not part of it). - // OrphanStatus bool `json:"orphan_status"` - // PowHash TODO - // + // PowHash is the slow hash of the block found by miners PowHash string `json:"pow_hash"` - // PrevHash is the hash of the block immediately preceding this - // block in the chain. - // + // PrevHash is the hash of the block immediately preceding this block in the chain. PrevHash string `json:"prev_hash"` // Reward the amount of new atomic-units generated in this - // block and rewarded to the miner (1XMR = 1e12 atomic units). - // + // block and rewarded to the miner (1 XMR = 1e12 atomic units). Reward uint64 `json:"reward"` - // Timestamp is the unix timestamp at which the block was - // recorded into the blockchain. - // + // Timestamp is the UNIX timestamp in seconds at which the block was added into the blockchain. Timestamp int64 `json:"timestamp"` // WideCumulativeDifficulty is the cumulative difficulty of all // blocks in the blockchain as a hexadecimal string // representing a 128-bit number. - // WideCumulativeDifficulty string `json:"wide_cumulative_difficulty"` // WideDifficulty is the network difficulty as a hexadecimal // string representing a 128-bit number. - // WideDifficulty string `json:"wide_difficulty"` } @@ -529,20 +474,16 @@ type GetBlockRequestParameters struct { // GetBlockResult is the result of a call to the GetBlock RPC method. type GetBlockResult struct { // Blob is a hexadecimal representation of the block. - // Blob string `json:"blob"` // BlockHeader contains the details from the block header. - // BlockHeader BlockHeader `json:"block_header"` // JSON is a json representation of the block - see // `GetBlockResultJSON`. - // JSON string `json:"json"` // MinerTxHash is the hash of the coinbase transaction - // MinerTxHash string `json:"miner_tx_hash"` RPCResultFooter `json:",inline"` @@ -551,39 +492,30 @@ type GetBlockResult struct { // GetBlockResultJSON is the internal json-formatted block information. type GetBlockResultJSON struct { // MajorVersion (same as in the block header) - // MajorVersion uint `json:"major_version"` // MinorVersion (same as in the block header) - // MinorVersion uint `json:"minor_version"` // Timestamp (same as in the block header) - // Timestamp uint64 `json:"timestamp"` // PrevID (same as `block_hash` in the block header) - // PrevID string `json:"prev_id"` // Nonce (same as in the block header) - // - Nonce int `json:"nonce"` + Nonce uint32 `json:"nonce"` // MinerTx contains the miner transaction information. - // MinerTx struct { // Version is the transaction version number - // Version int `json:"version"` // UnlockTime is the block height when the coinbase transaction // becomes spendable. - // UnlockTime int `json:"unlock_time"` // Vin lists the transaction inputs. - // Vin []struct { Gen struct { Height int `json:"height"` @@ -591,7 +523,6 @@ type GetBlockResultJSON struct { } `json:"vin"` // Vout lists the transaction outputs. - // Vout []struct { Amount uint64 `json:"amount"` Target struct { @@ -600,13 +531,10 @@ type GetBlockResultJSON struct { } `json:"vout"` // Extra (aka the transaction id) can be used to include any // random 32byte/64char hex string. - // Extra []int `json:"extra"` // RctSignatures contain the signatures of tx signers. - // // ps.: coinbase txs DO NOT have signatures. - // RctSignatures struct { Type int `json:"type"` } `json:"rct_signatures"` @@ -614,7 +542,6 @@ type GetBlockResultJSON struct { // TxHashes is the list of hashes of non-coinbase transactions in the // block. - // TxHashes []string `json:"tx_hashes"` } @@ -860,12 +787,9 @@ type GetTransactionPoolResult struct { type SetLogCategoriesRequestParameters struct { // Categories to log with their corresponding levels formatted as a // comma-separated list of : pairs. - // // For instance, to activate verbosity 1 for the `net.http` category // and verbosity 4 for `net.dns`: - // // net.htpp:1,net.dns:4 - // Categories string `json:"categories"` } @@ -877,7 +801,6 @@ type SetLogCategoriesResult struct { type SetLogLevelRequestParameters struct { // Level is the log level that the daemon should use. From 0 to 4 (less // verbose to more verbose). - // Level int8 `json:"level"` } @@ -887,19 +810,15 @@ type SetLogLevelResult struct { type SetLimitRequestParameters struct { // LimitUp is the upload limit in kB/s - // LimitUp uint64 `json:"limit_up"` // LimitDown is the download limit in kB/s - // LimitDown uint64 `json:"limit_down"` } type SetLimitResult struct { // LimitUp is the upload limit in kB/s - // LimitUp uint64 `json:"limit_up"` - // LimitDOwn is the download limit in kB/s - // + // LimitDown is the download limit in kB/s LimitDown uint64 `json:"limit_down"` RPCResultFooter `json:",inline"` @@ -907,10 +826,8 @@ type SetLimitResult struct { type GetLimitResult struct { // LimitUp is the upload limit in kB/s - // LimitUp uint64 `json:"limit_up"` // LimitDown is the download limit in kB/s - // LimitDown uint64 `json:"limit_down"` RPCResultFooter `json:",inline"` diff --git a/rpc/wallet/jsonrpc.go b/rpc/wallet/jsonrpc.go index 71534c2..8f81a9f 100644 --- a/rpc/wallet/jsonrpc.go +++ b/rpc/wallet/jsonrpc.go @@ -116,7 +116,18 @@ func (c *Client) GetHeight(ctx context.Context) (*GetHeightResult, error) { func (c *Client) Transfer(ctx context.Context, params TransferParameters) (*TransferResult, error) { resp := &TransferResult{} - if err := c.JSONRPC(ctx, "transfer", nil, resp); err != nil { + if err := c.JSONRPC(ctx, "transfer", params, resp); err != nil { + return nil, fmt.Errorf("jsonrpc: %w", err) + } + + return resp, nil +} + +// Same as Transfer, but can split into more than one tx if necessary +func (c *Client) TransferSplit(ctx context.Context, params TransferParameters) (*TransferSplitResult, error) { + resp := &TransferSplitResult{} + + if err := c.JSONRPC(ctx, "transfer_split", params, resp); err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } @@ -126,9 +137,20 @@ func (c *Client) Transfer(ctx context.Context, params TransferParameters) (*Tran func (c *Client) IncomingTransfers(ctx context.Context, params IncomingTransfersParams) (*IncomingTransfersResult, error) { resp := &IncomingTransfersResult{} - if err := c.JSONRPC(ctx, "incoming_transfers", nil, resp); err != nil { + if err := c.JSONRPC(ctx, "incoming_transfers", params, resp); err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } return resp, nil } + +func (c *Client) SweepAll(ctx context.Context, params SweepAllParams) (*SweepAllResult, error) { + resp := &SweepAllResult{} + + if err := c.JSONRPC(ctx, "sweep_all", params, resp); err != nil { + return nil, fmt.Errorf("jsonrpc: %w", err) + } + + return resp, nil + +} diff --git a/rpc/wallet/jsonrpc_types.go b/rpc/wallet/jsonrpc_types.go index fed460a..2dcbd80 100644 --- a/rpc/wallet/jsonrpc_types.go +++ b/rpc/wallet/jsonrpc_types.go @@ -114,6 +114,17 @@ type TransferResult struct { TxMetadata string `json:"tx_metadata"` UnsignedTxset string `json:"unsigned_txset"` } +type TransferSplitResult struct { + TxHashList []string `json:"tx_hash_list"` + TxKeyList []string `json:"tx_key_list"` + AmountList []uint64 `json:"amount_list"` + FeeList []uint64 `json:"fee_list"` + WeightList []uint64 `json:"weight_list"` + TxBlobList []string `json:"tx_blob_list"` + TxMetadataList []string `json:"tx_metadata_list"` + MultisigTxset string `json:"multisig_txset"` + UnsignedTxset string `json:"unsigned_txset"` +} type SubaddrIndices struct { Major uint `json:"major"` // Account index for the subaddress. @@ -140,3 +151,26 @@ type IncomingTransfersParams struct { type IncomingTransfersResult struct { Transfers []Transfer `json:"transfers"` } + +type SweepAllParams struct { + Address string `json:"address"` // Destination public address. + AccountIndex uint `json:"account_index"` // Sweep transactions from this account. + SubaddrIndices []uint `json:"subaddr_indices,omitempty"` // Sweep from this set of subaddresses in the account. + Priority uint8 `json:"priority,omitempty"` // Priority for sending the sweep transfer, partially determines fee. + Outputs uint `json:"outputs,omitempty"` // Specify the number of separate outputs that will be created. + UnlockTime uint64 `json:"unlock_time,omitempty"` // Number of blocks before the coins can be spent. + PaymentId string `json:"payment_id,omitempty"` // The 16-bytes payment ID encoded as hex. + GetTxKeys bool `json:"get_tx_keys,omitempty"` // Return the transaction keys after sending. + DoNotRelay bool `json:"do_not_relay,omitempty"` // If true, do not relay this sweep transfer. + GetTxHex bool `json:"get_tx_hex,omitempty"` // Return the transaction as hex after sending. + GetTxMetadata bool `json:"get_tx_metadata,omitempty"` // Return the transaction metadata after sending. +} + +type SweepAllResult struct { + TxHashList []string `json:"tx_hash_list"` + TxKeyList []string `json:"tx_key_list"` + AmountList []uint64 `json:"amount_list"` + FeeList []uint64 `json:"fee_list"` + WeightList []uint64 `json:"weight_list"` + TxBlobList []string `json:"tx_blob_list"` +}