Skip to content

Commit fa2aebd

Browse files
authored
Merge pull request #113 from markuslevonyak/support-for-inflatable-fungible-assets
feat: support for inflatable fungible assets
2 parents 9181763 + bfeb557 commit fa2aebd

File tree

11 files changed

+518
-28
lines changed

11 files changed

+518
-28
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ The node currently exposes the following APIs:
218218
- `/getchannelid` (POST)
219219
- `/getpayment` (POST)
220220
- `/getswap` (POST)
221+
- `/inflate` (POST)
221222
- `/init` (POST)
222223
- `/invoicestatus` (POST)
223224
- `/issueassetcfa` (POST)
225+
- `/issueassetifa` (POST)
224226
- `/issueassetnia` (POST)
225227
- `/issueassetuda` (POST)
226228
- `/keysend` (POST)

openapi.yaml

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,24 @@ paths:
386386
application/json:
387387
schema:
388388
$ref: '#/components/schemas/GetSwapResponse'
389+
/inflate:
390+
post:
391+
tags:
392+
- RGB
393+
summary: Inflate RGB assets
394+
description: Inflate RGB assets on-chain
395+
requestBody:
396+
content:
397+
application/json:
398+
schema:
399+
$ref: '#/components/schemas/InflateRequest'
400+
responses:
401+
'200':
402+
description: Successful operation
403+
content:
404+
application/json:
405+
schema:
406+
$ref: '#/components/schemas/InflateResponse'
389407
/init:
390408
post:
391409
tags:
@@ -442,6 +460,24 @@ paths:
442460
application/json:
443461
schema:
444462
$ref: '#/components/schemas/IssueAssetCFAResponse'
463+
/issueassetifa:
464+
post:
465+
tags:
466+
- RGB
467+
summary: Issue an RGB IFA asset
468+
description: Issue an RGB IFA asset
469+
requestBody:
470+
content:
471+
application/json:
472+
schema:
473+
$ref: '#/components/schemas/IssueAssetIFARequest'
474+
responses:
475+
'200':
476+
description: Successful operation
477+
content:
478+
application/json:
479+
schema:
480+
$ref: '#/components/schemas/IssueAssetIFAResponse'
445481
/issueassetnia:
446482
post:
447483
tags:
@@ -1056,6 +1092,63 @@ components:
10561092
oneOf:
10571093
- $ref: '#/components/schemas/Media'
10581094
- type: 'null'
1095+
AssetIFA:
1096+
type: object
1097+
required:
1098+
- asset_id
1099+
- ticker
1100+
- name
1101+
- precision
1102+
- initial_supply
1103+
- max_supply
1104+
- known_circulating_supply
1105+
- timestamp
1106+
- added_at
1107+
- balance
1108+
properties:
1109+
asset_id:
1110+
type: string
1111+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
1112+
ticker:
1113+
type: string
1114+
example: USDT
1115+
name:
1116+
type: string
1117+
example: Tether
1118+
details:
1119+
type:
1120+
- string
1121+
- 'null'
1122+
example: asset details
1123+
precision:
1124+
type: integer
1125+
example: 0
1126+
initial_supply:
1127+
type: integer
1128+
example: 777
1129+
max_supply:
1130+
type: integer
1131+
example: 999
1132+
known_circulating_supply:
1133+
type: integer
1134+
example: 888
1135+
timestamp:
1136+
type: integer
1137+
example: 1691160565
1138+
added_at:
1139+
type: integer
1140+
example: 1691161979
1141+
balance:
1142+
$ref: '#/components/schemas/AssetBalanceResponse'
1143+
media:
1144+
oneOf:
1145+
- $ref: '#/components/schemas/Media'
1146+
- type: 'null'
1147+
reject_list_url:
1148+
type:
1149+
- string
1150+
- 'null'
1151+
example: https://some.domain/someasset/rejectlist
10591152
AssetMetadataRequest:
10601153
type: object
10611154
required:
@@ -1159,6 +1252,7 @@ components:
11591252
- Nia
11601253
- Uda
11611254
- Cfa
1255+
- Ifa
11621256
AssetUDA:
11631257
type: object
11641258
required:
@@ -1742,6 +1836,37 @@ components:
17421836
enum:
17431837
- Electrum
17441838
- Esplora
1839+
InflateRequest:
1840+
type: object
1841+
required:
1842+
- asset_id
1843+
- inflation_amounts
1844+
- fee_rate
1845+
- min_confirmations
1846+
properties:
1847+
asset_id:
1848+
type: string
1849+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
1850+
inflation_amounts:
1851+
type: array
1852+
items:
1853+
type: integer
1854+
minItems: 1
1855+
example: [ 100, 50 ]
1856+
fee_rate:
1857+
type: integer
1858+
example: 5
1859+
min_confirmations:
1860+
type: integer
1861+
example: 1
1862+
InflateResponse:
1863+
type: object
1864+
required:
1865+
- txid
1866+
properties:
1867+
txid:
1868+
type: string
1869+
example: 7c2c95b9c2aa0a7d140495b664de7973b76561de833f0dd84def3efa08941664
17451870
InitRequest:
17461871
type: object
17471872
required:
@@ -1820,6 +1945,51 @@ components:
18201945
properties:
18211946
asset:
18221947
$ref: '#/components/schemas/AssetCFA'
1948+
IssueAssetIFARequest:
1949+
type: object
1950+
required:
1951+
- amounts
1952+
- inflation_amounts
1953+
- ticker
1954+
- name
1955+
- precision
1956+
- replace_rights_num
1957+
properties:
1958+
amounts:
1959+
type: array
1960+
items:
1961+
type: integer
1962+
minItems: 1
1963+
example: [ 1000, 600 ]
1964+
inflation_amounts:
1965+
type: array
1966+
items:
1967+
type: integer
1968+
example: [ 100, 50 ]
1969+
ticker:
1970+
type: string
1971+
example: USDT
1972+
name:
1973+
type: string
1974+
example: Tether
1975+
precision:
1976+
type: integer
1977+
example: 0
1978+
replace_rights_num:
1979+
type: integer
1980+
example: 0
1981+
reject_list_url:
1982+
type:
1983+
- string
1984+
- 'null'
1985+
example: https://some.domain/someasset/rejectlist
1986+
IssueAssetIFAResponse:
1987+
type: object
1988+
required:
1989+
- asset
1990+
properties:
1991+
asset:
1992+
$ref: '#/components/schemas/AssetIFA'
18231993
IssueAssetNIARequest:
18241994
type: object
18251995
required:
@@ -1934,13 +2104,14 @@ components:
19342104
type: array
19352105
items:
19362106
$ref: '#/components/schemas/AssetSchema'
1937-
example: [ Nia, Uda, Cfa ]
2107+
example: [ Nia, Uda, Cfa, Ifa ]
19382108
ListAssetsResponse:
19392109
type: object
19402110
required:
19412111
- nia
19422112
- uda
19432113
- cfa
2114+
- ifa
19442115
properties:
19452116
nia:
19462117
type:
@@ -1960,6 +2131,12 @@ components:
19602131
- 'null'
19612132
items:
19622133
$ref: '#/components/schemas/AssetCFA'
2134+
ifa:
2135+
type:
2136+
- array
2137+
- 'null'
2138+
items:
2139+
$ref: '#/components/schemas/AssetIFA'
19632140
ListChannelsResponse:
19642141
type: object
19652142
required:

rust-lightning

src/error.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ pub enum APIError {
293293
#[error("The provided backup has an unsupported version: {version}")]
294294
UnsupportedBackupVersion { version: String },
295295

296+
#[error("Inflation is not supported by schema {0}")]
297+
UnsupportedInflation(String),
298+
296299
#[error("Layer 1 {0} is not supported")]
297300
UnsupportedLayer1(String),
298301

@@ -386,16 +389,25 @@ impl From<RgbLibError> for APIError {
386389
RgbLibError::MaxFeeExceeded { txid } => APIError::MaxFeeExceeded(txid),
387390
RgbLibError::MinFeeNotMet { txid } => APIError::MinFeeNotMet(txid),
388391
RgbLibError::Network { details } => APIError::Network(details),
392+
RgbLibError::NoInflationAmounts => {
393+
APIError::InvalidAmount(s!("inflation request with no amounts or zero amounts"))
394+
}
389395
RgbLibError::NoIssuanceAmounts => {
390396
APIError::InvalidAmount(s!("issuance request with no provided amounts"))
391397
}
392398
RgbLibError::NoValidTransportEndpoint => APIError::NoValidTransportEndpoint,
393399
RgbLibError::OutputBelowDustLimit => APIError::OutputBelowDustLimit,
394400
RgbLibError::Proxy { details } => APIError::Network(format!("proxy err: {details}")),
395401
RgbLibError::RecipientIDAlreadyUsed => APIError::RecipientIDAlreadyUsed,
402+
RgbLibError::TooHighInflationAmounts => {
403+
APIError::InvalidAmount(s!("inflation amount exceeds the max possible supply"))
404+
}
396405
RgbLibError::TooHighIssuanceAmounts => {
397406
APIError::InvalidAmount(s!("trying to issue too many assets"))
398407
}
408+
RgbLibError::UnsupportedInflation { asset_schema } => {
409+
APIError::UnsupportedInflation(format!("{asset_schema}"))
410+
}
399411
RgbLibError::UnsupportedLayer1 { layer_1 } => APIError::UnsupportedLayer1(layer_1),
400412
RgbLibError::UnsupportedTransportType => APIError::UnsupportedTransportType,
401413
_ => {
@@ -506,6 +518,7 @@ impl IntoResponse for APIError {
506518
| APIError::UnknownLNInvoice
507519
| APIError::UnknownTemporaryChannelId
508520
| APIError::UnlockedNode
521+
| APIError::UnsupportedInflation(_)
509522
| APIError::UnsupportedLayer1(_)
510523
| APIError::UnsupportedTransportType => {
511524
(StatusCode::FORBIDDEN, self.to_string(), self.name())

src/ldk.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,10 @@ async fn handle_ldk_events(
593593
let channel_rgb_amount = rgb_info.local_rgb_amount + rgb_info.remote_rgb_amount;
594594
let asset_id = rgb_info.contract_id.to_string();
595595
let assignment = match rgb_info.schema {
596-
AssetSchema::Nia | AssetSchema::Cfa => Assignment::Fungible(channel_rgb_amount),
596+
AssetSchema::Nia | AssetSchema::Cfa | AssetSchema::Ifa => {
597+
Assignment::Fungible(channel_rgb_amount)
598+
}
597599
AssetSchema::Uda => Assignment::NonFungible,
598-
AssetSchema::Ifa => todo!(),
599600
};
600601

601602
let recipient_id = recipient_id_from_script_buf(script_buf, static_state.network);
@@ -1788,7 +1789,12 @@ pub(crate) async fn start_ldk(
17881789
master_fingerprint: master_fingerprint.to_string(),
17891790
mnemonic: Some(mnemonic.to_string()),
17901791
vanilla_keychain: None,
1791-
supported_schemas: vec![AssetSchema::Nia, AssetSchema::Cfa, AssetSchema::Uda],
1792+
supported_schemas: vec![
1793+
AssetSchema::Nia,
1794+
AssetSchema::Cfa,
1795+
AssetSchema::Uda,
1796+
AssetSchema::Ifa,
1797+
],
17921798
})
17931799
.expect("valid rgb-lib wallet")
17941800
})

src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ use crate::routes::{
4545
address, asset_balance, asset_metadata, backup, btc_balance, change_password,
4646
check_indexer_url, check_proxy_endpoint, close_channel, connect_peer, create_utxos,
4747
decode_ln_invoice, decode_rgb_invoice, disconnect_peer, estimate_fee, fail_transfers,
48-
get_asset_media, get_channel_id, get_payment, get_swap, init, invoice_status, issue_asset_cfa,
49-
issue_asset_nia, issue_asset_uda, keysend, list_assets, list_channels, list_payments,
50-
list_peers, list_swaps, list_transactions, list_transfers, list_unspents, ln_invoice, lock,
51-
maker_execute, maker_init, network_info, node_info, open_channel, post_asset_media,
52-
refresh_transfers, restore, revoke_token, rgb_invoice, send_btc, send_onion_message,
53-
send_payment, send_rgb, shutdown, sign_message, sync, taker, unlock,
48+
get_asset_media, get_channel_id, get_payment, get_swap, inflate, init, invoice_status,
49+
issue_asset_cfa, issue_asset_ifa, issue_asset_nia, issue_asset_uda, keysend, list_assets,
50+
list_channels, list_payments, list_peers, list_swaps, list_transactions, list_transfers,
51+
list_unspents, ln_invoice, lock, maker_execute, maker_init, network_info, node_info,
52+
open_channel, post_asset_media, refresh_transfers, restore, revoke_token, rgb_invoice,
53+
send_btc, send_onion_message, send_payment, send_rgb, shutdown, sign_message, sync, taker,
54+
unlock,
5455
};
5556
use crate::utils::{start_daemon, AppState, LOGS_DIR};
5657

@@ -124,9 +125,11 @@ pub(crate) async fn app(args: UserArgs) -> Result<(Router, Arc<AppState>), AppEr
124125
.route("/getchannelid", post(get_channel_id))
125126
.route("/getpayment", post(get_payment))
126127
.route("/getswap", post(get_swap))
128+
.route("/inflate", post(inflate))
127129
.route("/init", post(init))
128130
.route("/invoicestatus", post(invoice_status))
129131
.route("/issueassetcfa", post(issue_asset_cfa))
132+
.route("/issueassetifa", post(issue_asset_ifa))
130133
.route("/issueassetnia", post(issue_asset_nia))
131134
.route("/issueassetuda", post(issue_asset_uda))
132135
.route("/keysend", post(keysend))

0 commit comments

Comments
 (0)