forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
183 additions
and
1,142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/cactus-example-discounted-asset-trade-client/src/main/typescript/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./public-api"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
examples/cactus-example-discounted-asset-trade-client/src/main/typescript/public-api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./lib/agent-setup"; | ||
export * from "./lib/connections"; | ||
export * from "./lib/credentials"; | ||
export * from "./lib/proofs"; |
110 changes: 110 additions & 0 deletions
110
...unted-asset-trade-client/src/main/typescript/scripts/run-discounted-asset-trade-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Agent } from "@aries-framework/core"; | ||
import inquirer from "inquirer"; | ||
import * as log from "loglevel"; | ||
import { | ||
createAliceAgent, | ||
createNewConnectionInvitation, | ||
getAgentCredentials, | ||
waitForConnection, | ||
} from "../public-api"; | ||
|
||
log.setDefaultLevel("DEBUG"); | ||
|
||
enum PromptOptions { | ||
StartTrade = "Start the trade", | ||
GetCredentials = "Get this agent credentials", | ||
GetAssets = "Get assets", | ||
Exit = "Exit", | ||
} | ||
|
||
async function connectAgentToBLP(clientAgent: Agent) { | ||
log.debug("Connecting to the discounted asset trade sample app agent..."); | ||
|
||
// Create invitation | ||
const { outOfBandRecord, invitationUrl } = | ||
await createNewConnectionInvitation(clientAgent); | ||
const isConnectedPromise = waitForConnection(clientAgent, outOfBandRecord.id); | ||
|
||
// Send request to the BLP agent | ||
// TODO - send with HTTP | ||
log.debug("Invitation link:", invitationUrl); | ||
|
||
// Wait for connection | ||
await isConnectedPromise; | ||
log.info("Connected to the discounted asset trade sample app agent!"); | ||
} | ||
|
||
async function sendTradeRequest() { | ||
// TODO | ||
log.info("Trade request sent!"); | ||
} | ||
|
||
async function printAgentCredentials(agent: Agent) { | ||
const credentials = await getAgentCredentials(agent); | ||
log.info(JSON.stringify(credentials, undefined, 2)); | ||
} | ||
|
||
async function getAssetsFromSampleApp() { | ||
// TODO | ||
log.info("Assets: foo"); | ||
} | ||
|
||
async function getPromptChoice() { | ||
return inquirer.prompt({ | ||
type: "list", | ||
prefix: "", | ||
name: "menu", | ||
message: "Action:", | ||
choices: Object.values(PromptOptions), | ||
}); | ||
} | ||
|
||
async function menuLoop(agent: Agent) { | ||
let isRunning = true; | ||
|
||
while (isRunning) { | ||
try { | ||
const choice = await getPromptChoice(); | ||
switch (choice.menu) { | ||
case PromptOptions.StartTrade: | ||
await sendTradeRequest(); | ||
break; | ||
case PromptOptions.GetCredentials: | ||
await printAgentCredentials(agent); | ||
break; | ||
case PromptOptions.GetAssets: | ||
await getAssetsFromSampleApp(); | ||
break; | ||
case PromptOptions.Exit: | ||
isRunning = false; | ||
break; | ||
} | ||
} catch (error) { | ||
if (error.isTtyError) { | ||
log.error("Prompt couldn't be rendered in the current environment:"); | ||
isRunning = false; | ||
} else { | ||
log.error("Menu action error:", error); | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function run() { | ||
const aliceAgent = await createAliceAgent(); | ||
log.debug("Alice (client) agent created"); | ||
|
||
try { | ||
await connectAgentToBLP(aliceAgent); | ||
|
||
log.debug("Running menu loop..."); | ||
await menuLoop(aliceAgent); | ||
} catch (error) { | ||
log.error("Client app error:", error); | ||
} finally { | ||
log.info("Exiting the client app..."); | ||
aliceAgent.shutdown(); | ||
} | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.