This commit is contained in:
nitowa
2023-08-15 22:37:40 +02:00
parent d1d576edfa
commit bbe32c2c2d
7 changed files with 185 additions and 168 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
export const config = {
"oracle": true,
"secret": "sEdTP9Wkb4FSeaFhBavaob336sUTnqy",
"treasuryAddress": "rffH6RPq8xcKAWVvdYsiGEFrz1mz2iH3oj",
"contractAddress": "rDXi28Ud76cz9LtR2vAwsmGfqMcnfCTm8g", //pk: sEdSMv9Ztd2njbAhL3tTYqVRTKMQEME
"secret": "sEdVwoxNkoxvRxRDaShXwWzVUkrgztd",
"treasuryAddress": "rnhVAr4ri5aTBUfoEzi4PPgc5yVo7jrAa5",
"contractAddress": "rakoA9cbkj9SbArhsQAiYFqm1fYYeWvrji", //pk: sEdVYHB7KJuK8jB1HF6Q8HQq62izZ9f
"rippleNode": "wss://s.altnet.rippletest.net:51233",
}
-1
View File
@@ -15,6 +15,5 @@ const path = require('path');
await api.disconnect()
console.log("Done. Your upload is at: ", dataHash);
console.log("Building gateway ...")
child_process.exec(`DATA_HASH=${dataHash} npm run webpack-gateway`, console.log)
})()
@@ -14,7 +14,7 @@ export class ShoutboxDataService {
private userWallet1: any
private userWallet2: any
private shoutboxAddress = "rBnbBMZrbWEVHsyi1EWxv3gidzbreJzbgC"
private shoutboxAddress = "rBGqUNVzrNJ6CNpTriBts8QCTNi5VqUMnZ"
private rippleApi: any;
private xrpio: any;
@@ -28,11 +28,23 @@ export class ShoutboxDataService {
}
private submit = async (shoutHash: string) => {
return await this.xrpio.writeRaw({ data: shoutHash }, this.shoutboxAddress, this.userWallet1.secret)
const data = {
endpoint: 'submit',
data: shoutHash
}
console.log("Submitting shout root hash", data)
const submitTx = await this.xrpio.writeRaw({data: JSON.stringify(data)}, this.shoutboxAddress, this.userWallet1.secret)
console.log("submit TX @", submitTx)
return submitTx
}
public submitShout = async (shout: any) => {
console.log("writing shout data", shout)
const shoutHash = await this.xrpio.treeWrite(JSON.stringify(shout), this.userWallet1.address, this.userWallet2.secret)
console.log("shout data @ ", shoutHash)
return await this.submit(shoutHash)
}
+116
View File
@@ -0,0 +1,116 @@
import { Injectable } from "@angular/core";
import { DataParser } from "../util/Dataparser";
import { makeTestnetWallet } from "../util/TestnetUtils";
declare const xrpIO: any
declare const xrpl: any
const xrpNode = "wss://s.altnet.rippletest.net:51233"
@Injectable()
export class ShoutboxDataService {
public history: any[] = []
private userWallet1: any
private userWallet2: any
private shoutboxAddress = "rBGqUNVzrNJ6CNpTriBts8QCTNi5VqUMnZ"
private rippleApi: any;
private xrpio: any;
private getTransactions = async () => {
const resp = await this.rippleApi.request({
command: "account_tx",
account: this.shoutboxAddress,
forward: false,
})
return resp.result.transactions.map((entry: any) => entry.tx)
}
private submit = async (shoutHash: string) => {
const data = {
endpoint: 'submit',
data: shoutHash
}
console.log("Submitting shout root hash", data)
const submitTx = await this.xrpio.writeRaw({data: JSON.stringify(data)}, this.shoutboxAddress, this.userWallet1.secret)
console.log("submit TX @", submitTx)
return submitTx
}
public submitShout = async (shout: any) => {
console.log("writing shout data", shout)
const shoutHash = await this.xrpio.treeWrite(JSON.stringify(shout), this.userWallet1.address, this.userWallet2.secret)
console.log("shout data @ ", shoutHash)
return await this.submit(shoutHash)
}
private parseMemos = async (memos: any) => {
const shouts = await Promise.all(memos
.map((memo: any) => {
if (!memo.Memo || !memo.Memo.MemoData)
return
try {
return DataParser.parse('TxHash', hex_to_ascii(memo.Memo.MemoData))
} catch (e) {
return
}
})
.filter((hash: string) => hash != undefined)
.map((root_hash: string) => this.xrpio.treeRead([root_hash]))
)
return shouts.map((jsonStr: string) => JSON.parse(jsonStr))
}
private loadHistory = async () => {
const raw_txs = await this.getTransactions()
return await this.parseMemos(raw_txs.flatMap((htx: any) => htx.Memos))
}
private subscribeTxs = async (callback: Function) => {
this.rippleApi.on('transaction', (tx: any) => callback(tx))
await this.rippleApi.connection.request({
command: 'subscribe',
accounts: [this.shoutboxAddress]
})
}
private listen = async () => {
await this.subscribeTxs(async (raw_tx: any) => {
const shouts = await this.parseMemos(raw_tx.transaction.Memos)
this.history.unshift(...shouts)
})
}
initialize = async () => {
this.userWallet1 = await makeTestnetWallet()
this.userWallet2 = await makeTestnetWallet()
this.rippleApi = new xrpl.Client(xrpNode)
await this.rippleApi.connect()
this.xrpio = new xrpIO(xrpNode);
await this.xrpio.connect()
this.history = await this.loadHistory()
await this.listen();
}
}
export function initShoutboxSvc(svc: ShoutboxDataService): () => Promise<any> {
return svc.initialize;
}
function hex_to_ascii(input: any) {
var hex = input.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2) {
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
}
return str;
}
+2 -2
View File
@@ -10,8 +10,8 @@
<base href="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script src="https://cdn.jsdelivr.net/npm/xrpl@2.1.1"></script>
<script src="https://cdn.jsdelivr.net/npm/xrpio@0.1.7/lib/browser/xrpio.browser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xrpl@2.7.0"></script>
<script src="https://cdn.jsdelivr.net/npm/xrpio@0.1.8/lib/browser/xrpio.browser.js"></script>
</head>
<body cds-text="body">