Hey, DAML Community! It’s been a while… but I am back to working on our front end. Our goal is to be able to deploy to DABL for some testing/demo’ing.
Our current demo runs in Sandbox on SDK version 0.13.34. It is based on the old JavaScript repo called “daml-ui-template” (circa 12/2019, I couldn’t find it in current repos) which has since been replaced by a newer vision in Typescript. @georg and @bernhard helped answer a lot of questions that I had.
I am looking for some advice as to how best to approach upgrading.
So far, I have updated the JWT token, and have gotten the daml code to upload in a .dar using the updated sdk.
Next, I updated the LedgerContext.js
file with updated url’s (both POST and GET), and then a command with the updated payload.
Here is a snippet from the LedgerContext.js
files :
export async function sendCommand(dispatch, token, party, commandType, command, setIsSending, setError) {
setError(false);
setIsSending(true);
if (!!token) {
dispatch({ type: "COMMAND_SEND"});
try {
const headers = { "Content-Type": "application/json", "Authorization": "Bearer " + token };
if (!!party) { headers["X-DA-Party"] = party; }
const options = { method: "POST", headers, body: JSON.stringify(command) };
console.log(options);
const response = await fetch("/command/" + commandType, options);
const res = await response.json();
if (res.status !== 200) throw new Error(res.errors);
dispatch({ type: "COMMAND_SENT" });
setIsSending(false);
}
catch (error) {
console.log(error)
dispatch({ type: "COMMAND_ERROR", error });
setError(true);
setIsSending(false);
}
} else {
console.log("No token found")
dispatch({ type: "COMMAND_ERROR", error: "No token found" });
setError(true);
setIsSending(false);
}
}
export async function sendCommand(dispatch, token, party, commandType, command, setIsSending, setError) {
setError(false);
setIsSending(true);
if (!!token) {
dispatch({ type: "COMMAND_SEND"});
try {
const headers = { "Content Type": "application/json", "Authorization": "Bearer " + token };
if (!!party) { headers["X-DA-Party"] = party; }
const options = { method: "POST", headers, body: JSON.stringify(command) };
console.log(options);
const response = await fetch("/command/" + commandType, options);
const res = await response.json();
if (res.status !== 200) throw new Error(res.errors);
dispatch({ type: "COMMAND_SENT" });
setIsSending(false);
}
catch (error) {
console.log(error)
dispatch({ type: "COMMAND_ERROR", error });
setError(true);
setIsSending(false);
}
} else {
console.log("No token found")
dispatch({ type: "COMMAND_ERROR", error: "No token found" });
setError(true);
setIsSending(false);
}
}
export async function fetchContracts(dispatch, token, setIsFetching, setError) {
setError(false);
setIsFetching(true);
if (!!token) {
dispatch({ type: "CONTRACT_REQUEST"});
try {
const options = { method: 'GET', headers: { "Authorization": "Bearer " + token } };
const response = await fetch("/v1/query", options);
const json = await response.json();
if (json.status !== 200) throw new Error(json.errors);
const contracts = [].concat.apply([], json.result);
dispatch({ type: "CONTRACT_RESPONSE", contracts });
setIsFetching(false);
}
catch (error) {
console.log(error)
dispatch({ type: "CONTRACT_ERROR", error });
setError(true);
setIsFetching(false);
}
} else {
console.log("No token found")
dispatch({ type: "CONTRACT_ERROR", error: "No token found" });
setError(true);
setIsFetching(false);
}
}
and a market setup command:
const inviteMarketParticipants = async ( ) => {
const command = {
templateId: "DA.RefApps.Bond.Test.MarketSetup:MarketSetupSignatureCreator" ,
payload: {
operator : "Operator",
regulator: "Regulator",
auctionAgent: "AuctionAgent",
bank1: "Bank1",
bank2: "Bank2",
bank3: "Bank3",
csd: "CSD",
issuer: "Issuer",
centralBank: "CentralBank",
signatories: [ "Operator" ],
status: "Proposed"
},
meta: { ledgerEffectiveTime: 0 }
};await sendCommand(ledgerDispatch, user.token, user.party, "v1/create", command, () => {}, () => {});
await fetchContracts(ledgerDispatch, user.token, () => {}, () => {});
}
After submitting this command, I get a response in the Sandbox (I never fixed the ‘/’ in the reference although I saw the thread on here about it).
C:\Users\James Jaworski\OneDrive\Optimis\DABL\Bloqbook-main>daml start --sandbox-option "--ledgerid=test" --sandbox-option "--address=localhost" --start-navigator "no" --json-api-option "--max-inbound-message-size=2000000000" --sandbox-option "--maxInboundMessageSize=2000000000"
Compiling test to a DAR.
Created .daml\dist\test-0.0.1.dar
Waiting for sandbox to start:
INFO: Slf4jLogger started
INFO: Listening on localhost:6865 over plain text.
____ ____
/ __/__ ____ ___/ / / ___ __ __
_\ \/ _ `/ _ \/ _ / _ \/ _ \\ \ /
/___/\_,_/_//_/\_,_/_.__/\___/_\_\
INFO: Initialized sandbox version 1.7.0 with ledger-id = test, port = 6865, dar file = List(.daml\dist\test-0.0.1.dar), time mode = wall-clock time, ledger = in-memory, auth-service = AuthServiceWildcard$, contract ids seeding = strong
Waiting for JSON API to start:
21:23:06.097 [main] INFO com.daml.http.Main$ - Config(ledgerHost=localhost, ledgerPort=6865, address=127.0.0.1, httpPort=7575, portFile=None, packageReloadInterval=5 seconds, packageMaxInboundMessageSize=None, maxInboundMessageSize=2000000000, tlsConfig=TlsConfiguration(false,None,None,None,REQUIRE), jdbcConfig=None, staticContentConfig=None, allowNonHttps=true, accessTokenFile=None, wsConfig=None)
21:23:06.988 [http-json-ledger-api-akka.actor.default-dispatcher-6] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
21:23:11.081 [http-json-ledger-api-akka.actor.default-dispatcher-12] INFO com.daml.http.HttpService$ - Connected to Ledger: test
21:23:11.083 [http-json-ledger-api-akka.actor.default-dispatcher-12] INFO com.daml.http.HttpService$ - contractDao: None
21:23:13.282 [http-json-ledger-api-akka.actor.default-dispatcher-12] INFO com.daml.http.PackageService - new package IDs loaded: c1f1f00558799eec139fb4f4c76f95fb52fa1837a5dd29600baa1c8ed1bdccfd, 733e38d36a2759688a4b2c4cec69d48e7b55ecc8dedc8067b815926c917a182a, bfcd37bd6b84768e86e432f5f6c33e25d9e7724a9d42e33875ff74f6348e733f, 518032f41fd0175461b35ae0c9691e08b4aea55e62915f8360af2cc7a1f2ba6c, cc348d369011362a5190fe96dd1f0dfbc697fdfd10e382b9e9666f0da05961b7, 6839a6d3d430c569b2425e9391717b44ca324b88ba621d597778811b2d05031d, 99a2705ed38c1c26cbb8fe7acf36bbf626668e167a33335de932599219e0a235, 76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f, e22bce619ae24ca3b8e6519281cb5a33b64b3190cc763248b4c3f9ad5087a92c, d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97, 6c2c0667393c5f92f1885163068cd31800d2264eb088eb6fc740e11241b2bf06, d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662, 057eed1fd48c238491b8ea06b9b5bf85a5d4c9275dd3f6183e0e6b01730cc2ba, e491352788e56ca4603acc411ffe1a49fefd76ed8b163af86cf5ee5f4c38645b, 40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7, 5894d748a7e97b8fd49ca4dab20543066ad2fcfb4435ae2062cbc335bbb69734, ac9677ef0dcbb2cac09a2f9c90aae9896f225a20a34bb1f9248ffb8c4bec7594, 6b6225f8dcc21acc170630698c97cce8fe47abc93daef3254945f5b6e7ecaa11, 8a7806365bbd98d88b4c13832ebfa305f6abaeaf32cfa2b7dd25c4fa489b79fb
21:23:14.506 [http-json-ledger-api-akka.actor.default-dispatcher-12] INFO com.daml.http.Main$ - Started server: ServerBinding(/127.0.0.1:7575)
..
Press 'r' + 'Enter' to re-build and upload the package to the sandbox.
Press 'Ctrl-C' to quit.
21:35:52.362 [http-json-ledger-api-akka.actor.default-dispatcher-11] WARN akka.actor.ActorSystemImpl - Illegal header: Illegal 'origin' header: Illegal origin: Invalid input '/', expected DIGIT or 'EOI' (line 1, column 22): http://localhost:7575/
^
21:50:02.700 [http-json-ledger-api-akka.actor.default-dispatcher-11] WARN akka.actor.ActorSystemImpl - Illegal header: Illegal 'origin' header: Illegal origin: Invalid input '/', expected DIGIT or 'EOI' (line 1, column 22): http://localhost:7575/
However, in my Sandbox.log file, the only output in the log is from when I started the ledger. So it looks to me like no command is ever received (there was no 200 | 400 | 404 | or ther response code).
21:22:49.016 [sandbox-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
21:23:04.172 [pool-1-thread-2] INFO c.d.p.apiserver.LedgerApiServer - Listening on localhost:6865 over plain text.
21:23:04.205 [pool-1-thread-5] INFO com.daml.platform.sandboxnext.Runner - Initialized sandbox version 1.7.0 with ledger-id = test, port = 6865, dar file = List(.daml\dist\test-0.0.1.dar), time mode = wall-clock time, ledger = in-memory, auth-service = AuthServiceWildcard$, contract ids seeding = strong
This has me wondering a few things:
- Does this approach make sense?
- Is there another part of the code that I should be updating to make calls according to the new sdk?
- What other factors (for DABL’s sake) should I be considering when making this upgrade?
Thanks!