|
@@ -1,4 +1,4 @@
|
1
|
|
-import { Injectable } from "@angular/core";
|
|
1
|
+import { ChangeDetectorRef, Injectable, NgZone } from "@angular/core";
|
2
|
2
|
import { z } from 'zod';
|
3
|
3
|
|
4
|
4
|
declare const RJSVM: any;
|
|
@@ -11,16 +11,18 @@ const listeningAddress = "rMBYWyxGx1b5zEjJKF18TTwF5X3vP2WyjR"
|
11
|
11
|
@Injectable()
|
12
|
12
|
export class ShoutboxDataService {
|
13
|
13
|
|
14
|
|
- public history: any[] = []
|
15
|
14
|
private dataWriter = undefined as any
|
16
|
15
|
|
|
16
|
+ constructor(
|
|
17
|
+ ) { }
|
|
18
|
+
|
17
|
19
|
public submitShout = async (shout: any) => {
|
18
|
20
|
return await this.dataWriter.callEndpoint('submit', shout, 10)
|
19
|
21
|
}
|
20
|
22
|
|
21
|
23
|
public getContractAddress = () => listeningAddress
|
22
|
24
|
|
23
|
|
- initialize = async (onData:Function, userWallet?:any, drainWallet?:any) => {
|
|
25
|
+ initialize = async (onData: Function, userWallet?: any, drainWallet?: any) => {
|
24
|
26
|
|
25
|
27
|
this.dataWriter = new Datawriter({
|
26
|
28
|
receiveAddress: drainWallet.address,
|
|
@@ -33,70 +35,69 @@ export class ShoutboxDataService {
|
33
|
35
|
title: z.string(),
|
34
|
36
|
body: z.string(),
|
35
|
37
|
from: z.string(),
|
|
38
|
+ hash: z.optional(z.string()),
|
|
39
|
+ date: z.optional(z.string()),
|
36
|
40
|
id: z.optional(z.string())
|
37
|
41
|
})
|
38
|
|
- //type Shout = z.infer<typeof shoutSchema>
|
39
|
|
-
|
40
|
|
- type State = {
|
41
|
|
- shouts: any[]
|
42
|
|
- }
|
43
|
|
-
|
|
42
|
+ type Shout = z.infer<typeof shoutSchema>
|
|
43
|
+
|
|
44
|
+ type State = {}
|
|
45
|
+
|
44
|
46
|
// #########################
|
45
|
47
|
// Define endpoints
|
46
|
48
|
// #########################
|
47
|
|
-
|
|
49
|
+
|
48
|
50
|
type RJSVM_Endpoints = {
|
49
|
|
- submit: (data: any) => void
|
|
51
|
+ submit: (data: Shout) => void
|
50
|
52
|
}
|
51
|
|
-
|
|
53
|
+
|
52
|
54
|
// #########################
|
53
|
55
|
// Define init state
|
54
|
56
|
// #########################
|
55
|
|
-
|
|
57
|
+
|
56
|
58
|
abstract class RJSVM_Base
|
57
|
59
|
extends RJSVM<State, RJSVM_Endpoints>
|
58
|
|
- {
|
59
|
|
-
|
|
60
|
+ {
|
|
61
|
+
|
60
|
62
|
owner = userWallet.address
|
61
|
|
-
|
62
|
|
- state: State = {
|
63
|
|
- shouts: []
|
64
|
|
- }
|
|
63
|
+
|
|
64
|
+ state: State = {}
|
65
|
65
|
}
|
66
|
|
-
|
|
66
|
+
|
67
|
67
|
// #########################
|
68
|
68
|
// Implement logic
|
69
|
69
|
// #########################
|
70
|
|
-
|
|
70
|
+
|
71
|
71
|
const RJSVM_Contract = {
|
72
|
72
|
submit: {
|
73
|
|
- implementation: function (env:any, shout: any) {
|
|
73
|
+ implementation: function (env: any, shout: Shout) {
|
74
|
74
|
shout.hash = env.hash;
|
75
|
|
- (this as any).state.shouts.unshift(shout)
|
|
75
|
+ const d = new Date("2000-01-01");
|
|
76
|
+ d.setSeconds(d.getSeconds() + env.date)
|
|
77
|
+ shout.date = d.toLocaleString("de-DE")
|
76
|
78
|
},
|
77
|
79
|
visibility: 'public',
|
78
|
80
|
fee: 10,
|
79
|
81
|
parameterSchema: shoutSchema
|
80
|
82
|
}
|
81
|
83
|
}
|
82
|
|
-
|
|
84
|
+
|
83
|
85
|
// #########################
|
84
|
86
|
// Build and connect
|
85
|
87
|
// #########################
|
86
|
|
-
|
|
88
|
+
|
87
|
89
|
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
|
88
|
|
-
|
|
90
|
+
|
89
|
91
|
const conf = {
|
90
|
92
|
listeningAddress: listeningAddress,
|
91
|
93
|
rippleNode: xrpNode
|
92
|
94
|
}
|
93
|
|
-
|
|
95
|
+
|
94
|
96
|
const rjsvm = new Rjsvm(conf)
|
95
|
97
|
await rjsvm.connect()
|
96
|
98
|
|
97
|
99
|
rjsvm.on('error', console.log)
|
98
|
100
|
rjsvm.on('submit', onData)
|
99
|
101
|
|
100
|
|
- this.history = rjsvm.state.shouts
|
101
|
102
|
}
|
102
|
103
|
}
|