Skip to content

Commit 457bbe3

Browse files
committed
Add MetaSponsorshipObject and dedupe FeeAmount/MaxFee in definitions.json
Every ledger entry has a Meta*Object counterpart except UnknownLedgerObject (intentional) and Sponsorship, which was missing one; add it, mirroring the ledger entry's fields, and register it in MetaLedgerEntryType. Also remove a byte-for-byte duplicate FeeAmount/MaxFee FIELDS entry in definitions.json (same nth/type), keeping the copy correctly grouped in ascending nth order alongside FeeAmountDelta.
1 parent 9dde910 commit 457bbe3

4 files changed

Lines changed: 197 additions & 20 deletions

File tree

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/metadata/MetaLedgerEntryType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public interface MetaLedgerEntryType {
6464
@Beta
6565
MetaLedgerEntryType LOAN = MetaLedgerEntryType.of("Loan");
6666

67+
@Beta
68+
MetaLedgerEntryType SPONSORSHIP = MetaLedgerEntryType.of("Sponsorship");
69+
6770

6871
/**
6972
* Construct a new {@link MetaLedgerEntryType} from a {@link String}.
@@ -137,6 +140,8 @@ default Class<? extends MetaLedgerObject> ledgerObjectType() {
137140
return MetaLoanBrokerObject.class;
138141
case "Loan":
139142
return MetaLoanObject.class;
143+
case "Sponsorship":
144+
return MetaSponsorshipObject.class;
140145
default:
141146
return MetaUnknownObject.class;
142147
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package org.xrpl.xrpl4j.model.transactions.metadata;
2+
3+
/*-
4+
* ========================LICENSE_START=================================
5+
* xrpl4j :: model
6+
* %%
7+
* Copyright (C) 2020 - 2022 XRPL Foundation and its contributors
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =========================LICENSE_END==================================
21+
*/
22+
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
25+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26+
import com.google.common.annotations.Beta;
27+
import com.google.common.primitives.UnsignedInteger;
28+
import org.immutables.value.Value;
29+
import org.xrpl.xrpl4j.model.client.common.LedgerIndex;
30+
import org.xrpl.xrpl4j.model.flags.SponsorshipFlags;
31+
import org.xrpl.xrpl4j.model.transactions.Address;
32+
import org.xrpl.xrpl4j.model.transactions.Hash256;
33+
import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount;
34+
35+
import java.util.Optional;
36+
37+
/**
38+
* Represents a pre-funded sponsorship relationship, as represented in transaction metadata.
39+
*
40+
* <p>This class will be marked {@link Beta} until the featureSponsorship amendment is enabled on mainnet.
41+
* Its API is subject to change.</p>
42+
*
43+
* @see "https://github.com/XRPLF/XRPL-Standards/blob/master/XLS-0068-sponsored-fees-and-reserves/README.md"
44+
*/
45+
@Beta
46+
@Value.Immutable
47+
@JsonSerialize(as = ImmutableMetaSponsorshipObject.class)
48+
@JsonDeserialize(as = ImmutableMetaSponsorshipObject.class)
49+
public interface MetaSponsorshipObject extends MetaLedgerObject {
50+
51+
/**
52+
* A bit-map of boolean flags enabled for this {@link MetaSponsorshipObject}.
53+
*
54+
* @return An {@link Optional} {@link SponsorshipFlags}.
55+
*/
56+
@JsonProperty("Flags")
57+
Optional<SponsorshipFlags> flags();
58+
59+
/**
60+
* The {@link Address} of the account that owns this sponsorship (the sponsor).
61+
*
62+
* @return An {@link Optional} {@link Address} of the sponsor account.
63+
*/
64+
@JsonProperty("Owner")
65+
Optional<Address> owner();
66+
67+
/**
68+
* The {@link Address} of the account being sponsored (the sponsee).
69+
*
70+
* @return An {@link Optional} {@link Address} of the sponsee account.
71+
*/
72+
@JsonProperty("Sponsee")
73+
Optional<Address> sponsee();
74+
75+
/**
76+
* The total amount of XRP (in drops) allocated for transaction fees.
77+
*
78+
* @return An {@link Optional} {@link XrpCurrencyAmount}.
79+
*/
80+
@JsonProperty("FeeAmount")
81+
Optional<XrpCurrencyAmount> feeAmount();
82+
83+
/**
84+
* The maximum fee (in drops) that can be charged for a single transaction using this sponsorship.
85+
*
86+
* @return An {@link Optional} {@link XrpCurrencyAmount}.
87+
*/
88+
@JsonProperty("MaxFee")
89+
Optional<XrpCurrencyAmount> maxFee();
90+
91+
/**
92+
* The number of reserve units sponsored for the sponsee.
93+
*
94+
* @return An {@link Optional} {@link UnsignedInteger}.
95+
*/
96+
@JsonProperty("RemainingOwnerCount")
97+
Optional<UnsignedInteger> remainingOwnerCount();
98+
99+
/**
100+
* A hint indicating which page of the owner directory link list this object is linked into.
101+
*
102+
* @return An {@link Optional} of type {@link String}.
103+
*/
104+
@JsonProperty("OwnerNode")
105+
Optional<String> ownerNode();
106+
107+
/**
108+
* A hint indicating which page of the sponsee directory link list this object is linked into.
109+
*
110+
* @return An {@link Optional} of type {@link String}.
111+
*/
112+
@JsonProperty("SponseeNode")
113+
Optional<String> sponseeNode();
114+
115+
/**
116+
* The identifying hash of the transaction that most recently modified this object.
117+
*
118+
* @return An {@link Optional} {@link Hash256}.
119+
*/
120+
@JsonProperty("PreviousTxnID")
121+
Optional<Hash256> previousTxnId();
122+
123+
/**
124+
* The index of the ledger that contains the transaction that most recently modified this object.
125+
*
126+
* @return An {@link Optional} {@link LedgerIndex}.
127+
*/
128+
@JsonProperty("PreviousTxnLgrSeq")
129+
Optional<LedgerIndex> previousTransactionLedgerSequence();
130+
131+
}

xrpl4j-core/src/main/resources/definitions.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,6 @@
7878
"type": "Unknown"
7979
}
8080
],
81-
[
82-
"FeeAmount",
83-
{
84-
"isSerialized": true,
85-
"isSigningField": true,
86-
"isVLEncoded": false,
87-
"nth": 32,
88-
"type": "Amount"
89-
}
90-
],
91-
[
92-
"MaxFee",
93-
{
94-
"isSerialized": true,
95-
"isSigningField": true,
96-
"isVLEncoded": false,
97-
"nth": 33,
98-
"type": "Amount"
99-
}
100-
],
10181
[
10282
"LedgerEntryType",
10383
{
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.xrpl.xrpl4j.model.transactions.metadata;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.google.common.primitives.UnsignedInteger;
5+
import org.json.JSONException;
6+
import org.junit.jupiter.api.Test;
7+
import org.xrpl.xrpl4j.model.AbstractJsonTest;
8+
import org.xrpl.xrpl4j.model.client.common.LedgerIndex;
9+
import org.xrpl.xrpl4j.model.flags.SponsorshipFlags;
10+
import org.xrpl.xrpl4j.model.transactions.Address;
11+
import org.xrpl.xrpl4j.model.transactions.Hash256;
12+
import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount;
13+
14+
class MetaSponsorshipObjectTest extends AbstractJsonTest {
15+
16+
@Test
17+
void testMetaSponsorshipObjectWithAllFields() throws JsonProcessingException, JSONException {
18+
MetaSponsorshipObject metaSponsorshipObject = ImmutableMetaSponsorshipObject.builder()
19+
.flags(SponsorshipFlags.REQUIRE_SIGN_FOR_FEE)
20+
.owner(Address.of("rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH"))
21+
.sponsee(Address.of("rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY"))
22+
.feeAmount(XrpCurrencyAmount.ofDrops(1000000))
23+
.maxFee(XrpCurrencyAmount.ofDrops(100))
24+
.remainingOwnerCount(UnsignedInteger.valueOf(5))
25+
.ownerNode("0000000000000000")
26+
.sponseeNode("0000000000000001")
27+
.previousTxnId(Hash256.of("7E5F3FB60E1177F8AF8A9EAC7982F27FA5494FDEA871B23B4B149939A5A7A7BB"))
28+
.previousTransactionLedgerSequence(LedgerIndex.of(UnsignedInteger.valueOf(82357607)))
29+
.build();
30+
31+
String json = "{" +
32+
" \"Flags\": 65536," +
33+
" \"Owner\": \"rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH\"," +
34+
" \"Sponsee\": \"rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY\"," +
35+
" \"FeeAmount\": \"1000000\"," +
36+
" \"MaxFee\": \"100\"," +
37+
" \"RemainingOwnerCount\": 5," +
38+
" \"OwnerNode\": \"0000000000000000\"," +
39+
" \"SponseeNode\": \"0000000000000001\"," +
40+
" \"PreviousTxnID\": \"7E5F3FB60E1177F8AF8A9EAC7982F27FA5494FDEA871B23B4B149939A5A7A7BB\"," +
41+
" \"PreviousTxnLgrSeq\": 82357607" +
42+
"}";
43+
44+
assertCanSerializeAndDeserialize(metaSponsorshipObject, json, MetaSponsorshipObject.class);
45+
}
46+
47+
@Test
48+
void testMetaSponsorshipObjectWithMinimalFields() throws JsonProcessingException, JSONException {
49+
MetaSponsorshipObject metaSponsorshipObject = ImmutableMetaSponsorshipObject.builder()
50+
.owner(Address.of("rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH"))
51+
.sponsee(Address.of("rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY"))
52+
.build();
53+
54+
String json = "{" +
55+
" \"Owner\": \"rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH\"," +
56+
" \"Sponsee\": \"rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY\"" +
57+
"}";
58+
59+
assertCanSerializeAndDeserialize(metaSponsorshipObject, json, MetaSponsorshipObject.class);
60+
}
61+
}

0 commit comments

Comments
 (0)