Skip to content

Commit 0090b33

Browse files
authored
Merge pull request #343 from Qortal/develop
Merge for update
2 parents dac844c + 7e8c109 commit 0090b33

31 files changed

Lines changed: 2684 additions & 270 deletions

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,5 +845,10 @@
845845
<artifactId>tika-core</artifactId>
846846
<version>${tika-core.version}</version>
847847
</dependency>
848+
<dependency>
849+
<groupId>com.fasterxml.jackson.core</groupId>
850+
<artifactId>jackson-databind</artifactId>
851+
<version>2.15.2</version> <!-- Use the latest stable version -->
852+
</dependency>
848853
</dependencies>
849854
</project>

src/main/java/org/qortal/api/resource/AtResource.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
import org.qortal.api.ApiException;
1515
import org.qortal.api.ApiExceptionFactory;
1616
import org.qortal.api.model.AtCreationRequest;
17+
import org.qortal.crosschain.BitcoinACCTv3;
18+
import org.qortal.crosschain.DigibyteACCTv3;
19+
import org.qortal.crosschain.DogecoinACCTv3;
20+
import org.qortal.crosschain.LitecoinACCTv3;
21+
import org.qortal.crosschain.PirateChainACCTv3;
22+
import org.qortal.crosschain.RavencoinACCTv3;
1723
import org.qortal.data.at.ATData;
24+
import org.qortal.data.at.ATDataDisplayDetail;
1825
import org.qortal.data.at.ATStateData;
1926
import org.qortal.data.transaction.DeployAtTransactionData;
2027
import org.qortal.repository.DataException;
@@ -33,7 +40,10 @@
3340
import javax.ws.rs.*;
3441
import javax.ws.rs.core.Context;
3542
import javax.ws.rs.core.MediaType;
43+
import java.util.ArrayList;
44+
import java.util.HashMap;
3645
import java.util.List;
46+
import java.util.Map;
3747

3848

3949
@Path("/at")
@@ -124,6 +134,75 @@ public ATData getByAddress(@PathParam("ataddress") String atAddress) {
124134
}
125135
}
126136

137+
@GET
138+
@Path("/executables")
139+
@Operation(
140+
summary = "Fetch info for all executable AT's",
141+
responses = {
142+
@ApiResponse(
143+
description = "all executable automated transactions",
144+
content = @Content(
145+
array = @ArraySchema(
146+
schema = @Schema(
147+
implementation = ATDataDisplayDetail.class
148+
)
149+
)
150+
)
151+
)
152+
}
153+
)
154+
@ApiErrors({
155+
ApiError.REPOSITORY_ISSUE
156+
})
157+
public List<ATDataDisplayDetail> getAllExecutableATs() {
158+
159+
List<ATDataDisplayDetail> details = new ArrayList<>();
160+
161+
Map<String, String> atNameByHash = new HashMap<>();
162+
163+
atNameByHash.put("9gS2L74FdaG3zuEeYv815xVyHkhvLguq7ZGD6pf24i8F", "q-fund version 1 - refund");
164+
atNameByHash.put("HaqJBVVr9gZqgARZ5UZd7EU9ybyvVK2fCo9sx3gMMFsr", "q-fund version 2 - no refund");
165+
atNameByHash.put("GA2GF79hfJeTy1TezS4sUZWS4vxJKs4qqwJ49h3NN8H9", "lottery");
166+
atNameByHash.put(Base58.encode(LitecoinACCTv3.CODE_BYTES_HASH), LitecoinACCTv3.NAME);
167+
atNameByHash.put(Base58.encode(BitcoinACCTv3.CODE_BYTES_HASH), BitcoinACCTv3.NAME);
168+
atNameByHash.put(Base58.encode(DogecoinACCTv3.CODE_BYTES_HASH), DogecoinACCTv3.NAME);
169+
atNameByHash.put(Base58.encode(DigibyteACCTv3.CODE_BYTES_HASH), DigibyteACCTv3.NAME);
170+
atNameByHash.put(Base58.encode(RavencoinACCTv3.CODE_BYTES_HASH), RavencoinACCTv3.NAME);
171+
atNameByHash.put(Base58.encode(PirateChainACCTv3.CODE_BYTES_HASH), PirateChainACCTv3.NAME);
172+
atNameByHash.put("5xwLAjTo1RyKLQS5gM1TvUvDR53H2ARCGyNwyyGcDp4q", "escrow v1-lite");
173+
174+
try (final Repository repository = RepositoryManager.getRepository()) {
175+
List<ATData> allExecutableATs = repository.getATRepository().getAllExecutableATs();
176+
177+
for( ATData executableAT : allExecutableATs) {
178+
executableAT.getCodeHash();
179+
180+
String codeHash58 = Base58.encode(executableAT.getCodeHash());
181+
182+
details.add(
183+
new ATDataDisplayDetail(
184+
executableAT.getATAddress(),
185+
executableAT.getCreatorPublicKey(),
186+
executableAT.getCreation(),
187+
executableAT.getIsSleeping(),
188+
executableAT.getIsFinished(),
189+
executableAT.getHadFatalError(),
190+
executableAT.getIsFrozen(),
191+
executableAT.getFrozenBalance(),
192+
codeHash58,
193+
atNameByHash.getOrDefault(codeHash58, "-")
194+
)
195+
);
196+
}
197+
198+
return details;
199+
} catch (ApiException e) {
200+
throw e;
201+
} catch (DataException e) {
202+
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
203+
}
204+
}
205+
127206
@GET
128207
@Path("/{ataddress}/data")
129208
@Operation(

src/main/java/org/qortal/api/resource/ChatResource.java

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
import org.qortal.api.ApiErrors;
1515
import org.qortal.api.ApiExceptionFactory;
1616
import org.qortal.api.Security;
17+
import org.qortal.controller.ChatTransactionDelegate;
1718
import org.qortal.crypto.Crypto;
1819
import org.qortal.data.chat.ActiveChats;
1920
import org.qortal.data.chat.ChatMessage;
2021
import org.qortal.data.transaction.ChatTransactionData;
2122
import org.qortal.data.transaction.TransactionData;
2223
import org.qortal.repository.DataException;
23-
import org.qortal.repository.Repository;
24-
import org.qortal.repository.RepositoryManager;
25-
import org.qortal.transaction.ChatTransaction;
26-
import org.qortal.transaction.Transaction;
2724
import org.qortal.transaction.Transaction.TransactionType;
2825
import org.qortal.transaction.Transaction.ValidationResult;
2926
import org.qortal.transform.TransformationException;
@@ -99,8 +96,8 @@ public List<ChatMessage> searchChat(@QueryParam("before") Long before, @QueryPar
9996
if (chatReference != null)
10097
chatReferenceBytes = Base58.decode(chatReference);
10198

102-
try (final Repository repository = RepositoryManager.getRepository()) {
103-
return repository.getChatRepository().getMessagesMatchingCriteria(
99+
try {
100+
return ChatTransactionDelegate.getInstance().getMessagesMatchingCriteria(
104101
before,
105102
after,
106103
txGroupId,
@@ -168,8 +165,8 @@ public int countChatMessages(@QueryParam("before") Long before, @QueryParam("aft
168165
if (chatReference != null)
169166
chatReferenceBytes = Base58.decode(chatReference);
170167

171-
try (final Repository repository = RepositoryManager.getRepository()) {
172-
return repository.getChatRepository().getMessagesMatchingCriteria(
168+
try {
169+
return ChatTransactionDelegate.getInstance().getMessagesMatchingCriteria(
173170
before,
174171
after,
175172
txGroupId,
@@ -202,16 +199,14 @@ public int countChatMessages(@QueryParam("before") Long before, @QueryParam("aft
202199
)
203200
@ApiErrors({ApiError.INVALID_CRITERIA, ApiError.INVALID_ADDRESS, ApiError.REPOSITORY_ISSUE})
204201
public ChatMessage getMessageBySignature(@PathParam("signature") String signature58, @QueryParam("encoding") Encoding encoding) {
205-
byte[] signature = Base58.decode(signature58);
202+
try {
206203

207-
try (final Repository repository = RepositoryManager.getRepository()) {
208-
209-
ChatTransactionData chatTransactionData = (ChatTransactionData) repository.getTransactionRepository().fromSignature(signature);
204+
ChatTransactionData chatTransactionData = ChatTransactionDelegate.getInstance().fromSignature(signature58);
210205
if (chatTransactionData == null) {
211206
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_CRITERIA, "Message not found");
212207
}
213208

214-
return repository.getChatRepository().toChatMessage(chatTransactionData, encoding);
209+
return ChatTransactionDelegate.getInstance().toChatMessage(chatTransactionData, encoding);
215210
} catch (DataException e) {
216211
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
217212
}
@@ -241,12 +236,8 @@ public ActiveChats getActiveChats(
241236
) {
242237
if (address == null || !Crypto.isValidAddress(address))
243238
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
244-
245-
try (final Repository repository = RepositoryManager.getRepository()) {
246-
return repository.getChatRepository().getActiveChats(address, encoding, hasChatReference);
247-
} catch (DataException e) {
248-
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
249-
}
239+
240+
return ChatTransactionDelegate.getInstance().getActiveChats(address, encoding, hasChatReference);
250241
}
251242

252243
@POST
@@ -279,19 +270,15 @@ public ActiveChats getActiveChats(
279270
public String buildChat(@HeaderParam(Security.API_KEY_HEADER) String apiKey, ChatTransactionData transactionData) {
280271
Security.checkApiCallAllowed(request);
281272

282-
try (final Repository repository = RepositoryManager.getRepository()) {
283-
ChatTransaction chatTransaction = (ChatTransaction) Transaction.fromData(repository, transactionData);
284-
285-
ValidationResult result = chatTransaction.isValidUnconfirmed();
273+
try {
274+
ValidationResult result = ChatTransactionDelegate.getInstance().isValid(transactionData, false);
286275
if (result != ValidationResult.OK)
287276
throw TransactionsResource.createTransactionInvalidException(request, result);
288277

289278
byte[] bytes = ChatTransactionTransformer.toBytes(transactionData);
290279
return Base58.encode(bytes);
291280
} catch (TransformationException e) {
292281
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSFORMATION_ERROR, e);
293-
} catch (DataException e) {
294-
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
295282
}
296283
}
297284

@@ -327,7 +314,7 @@ public String buildChat(@HeaderParam(Security.API_KEY_HEADER) String apiKey, Cha
327314
public String buildChat(@HeaderParam(Security.API_KEY_HEADER) String apiKey, String rawBytes58) {
328315
Security.checkApiCallAllowed(request);
329316

330-
try (final Repository repository = RepositoryManager.getRepository()) {
317+
try {
331318
byte[] rawBytes = Base58.decode(rawBytes58);
332319
// We're expecting unsigned transaction, so append empty signature prior to decoding
333320
rawBytes = Bytes.concat(rawBytes, new byte[TransactionTransformer.SIGNATURE_LENGTH]);
@@ -339,19 +326,17 @@ public String buildChat(@HeaderParam(Security.API_KEY_HEADER) String apiKey, Str
339326
if (transactionData.getType() != TransactionType.CHAT)
340327
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
341328

342-
ChatTransaction chatTransaction = (ChatTransaction) Transaction.fromData(repository, transactionData);
329+
if( !(transactionData instanceof ChatTransactionData) )
330+
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
331+
332+
ChatTransactionData chatTransactionData = (ChatTransactionData) transactionData;
343333

344334
// Quicker validity check first before we compute nonce
345-
ValidationResult result = chatTransaction.isValid();
335+
ValidationResult result = ChatTransactionDelegate.getInstance().isValid(chatTransactionData, false);
346336
if (result != ValidationResult.OK)
347337
throw TransactionsResource.createTransactionInvalidException(request, result);
348338

349-
chatTransaction.computeNonce();
350-
351-
// Re-check, but ignores signature
352-
result = chatTransaction.isValidUnconfirmed();
353-
if (result != ValidationResult.OK)
354-
throw TransactionsResource.createTransactionInvalidException(request, result);
339+
ChatTransactionDelegate.getInstance().computeNonce(chatTransactionData);
355340

356341
// Strip zeroed signature
357342
transactionData.setSignature(null);
@@ -360,8 +345,6 @@ public String buildChat(@HeaderParam(Security.API_KEY_HEADER) String apiKey, Str
360345
return Base58.encode(bytes);
361346
} catch (TransformationException e) {
362347
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSFORMATION_ERROR, e);
363-
} catch (DataException e) {
364-
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
365348
}
366349
}
367350

0 commit comments

Comments
 (0)