Skip to content

Commit e421271

Browse files
authored
Merge pull request #3 from vsbogd/get-payment-channel-state-from-daemon
First Java SDK version with usage example
2 parents fb98fd7 + 502a761 commit e421271

73 files changed

Lines changed: 3892 additions & 264 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
command: |
3939
curl -L https://get.web3j.io | bash
4040
source $HOME/.web3j/source.sh
41-
./get_contracts.sh
41+
./get_dependencies.sh
4242
# run tests!
4343
- run:
4444
name: Run tests

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.svg binary

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ hs_err_pid*
2424

2525
# maven build files
2626
target
27+
28+
# vim specific files
2729
*.swp
2830
.vim-project

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
## Class diagram
77

8-
![Class diagram](https://www.plantuml.com/plantuml/svg/VP9HJy8m58NV-olkupJ07v0G0aOpZMWOFXaVBkrbDAajQMz75lM_kusH30O-zlRqdFkTT1eOFSSl8mHhDWIPjdaqw3MN2s9umW8XktyMGbiclq59y4AC2XapTXvpWcy1i2wPFZuX9qxUbob4hs_knA-G1aE0TBS9Pu_4kSduPpIwA6mzbfJhmBwSEyiU9JUfhplMpg8PP-GBBQaLOJsTrCjScC_AL2KP-ueJdCzJDO3s50xYL3MhNm1-ywxGYdoJtLeVxpffnr7IgU2u_hcLw7atHLoLzseO3c-lgg7Nyd_gBd5BCZUQxA7gLGtuw7SouxXE7gALTPdZ-HQj9JE0rGIaivLlb5LMHGvGEAqWR2ChjxSBj-_sCSD09o7YDB9feI_g4TP0VPcOabNLf_u3)
9-
[Source code](https://www.planttext.com/?text=VP9HJy8m58NV-olkupJ07v0G0aOpZMWOFXaVBkrbDAajQMz75lM_kusH30O-zlRqdFkTT1eOFSSl8mHhDWIPjdaqw3MN2s9umW8XktyMGbiclq59y4AC2XapTXvpWcy1i2wPFZuX9qxUbob4hs_knA-G1aE0TBS9Pu_4kSduPpIwA6mzbfJhmBwSEyiU9JUfhplMpg8PP-GBBQaLOJsTrCjScC_AL2KP-ueJdCzJDO3s50xYL3MhNm1-ywxGYdoJtLeVxpffnr7IgU2u_hcLw7atHLoLzseO3c-lgg7Nyd_gBd5BCZUQxA7gLGtuw7SouxXE7gALTPdZ-HQj9JE0rGIaivLlb5LMHGvGEAqWR2ChjxSBj-_sCSD09o7YDB9feI_g4TP0VPcOabNLf_u3)
8+
![Class diagram](./docs/class-diagram.svg)
9+
[Source code](./docs/class-diagram.plantuml)
1010

1111
## How to build
1212

1313
Install dependencies for the first time:
1414
```
1515
curl -L https://get.web3j.io | bash
1616
source $HOME/.web3j/source.sh
17-
./get_contracts.sh
17+
./get_dependencies.sh
1818
```
1919

2020
Build and test:

docs/class-diagram.plantuml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
@startuml
2+
3+
title SingularityNet Java SDK
4+
5+
package io.singularitynet.sdk.ethereum {
6+
7+
interface WithAddress {
8+
Address getAddress();
9+
}
10+
11+
interface Signer {
12+
byte[] sign(byte[] message);
13+
}
14+
WithAddress <|-- Signer
15+
16+
class PrivateKeyIdentity
17+
Signer <|.. PrivateKeyIdentity
18+
19+
class MnemonicIdentity
20+
PrivateKeyIdentity <|-- MnemonicIdentity
21+
22+
}
23+
24+
25+
package io.singularitynet.sdk.registry {
26+
27+
interface MetadataStorage {
28+
byte[] get(URI uri);
29+
}
30+
class IpfsMetadataStorage
31+
MetadataStorage <|.. IpfsMetadataStorage
32+
33+
class RegistryContract {
34+
Optional<OrganizationRegistration> getOrganizationById(String orgId);
35+
Optional<ServiceRegistration> getServiceRegistrationById(String orgId, String serviceId);
36+
}
37+
38+
interface MetadataProvider {
39+
ServiceMetadata getServiceMetadata();
40+
}
41+
class RegistryMetadataProvider
42+
MetadataProvider <|.. RegistryMetadataProvider
43+
RegistryMetadataProvider *-- RegistryContract
44+
RegistryMetadataProvider *-- MetadataStorage
45+
46+
}
47+
48+
package io.singularitynet.sdk.daemon {
49+
50+
interface DaemonConnection {
51+
<T> T getGrpcStub(Function<Channel, T> constructor);
52+
void setClientCallsInterceptor(ClientInterceptor interceptor);
53+
void shutdownNow();
54+
}
55+
56+
class FirstEndpointDaemonConnection
57+
DaemonConnection <|.. FirstEndpointDaemonConnection
58+
FirstEndpointDaemonConnection o-- MetadataProvider
59+
60+
class PaymentChannelStateService {
61+
PaymentChannelStateReply getChannelState(BigInteger channelId);
62+
}
63+
PaymentChannelStateService o-- Signer
64+
PaymentChannelStateService -- DaemonConnection
65+
66+
interface Payment {
67+
void toMetadata(Metadata headers);
68+
}
69+
70+
}
71+
72+
package io.singularitynet.sdk.mpe {
73+
class MultiPartyEscrowContract {
74+
Optional<PaymentChannel> getChannelById(BigInteger channelId);
75+
Address getContractAddress();
76+
}
77+
78+
interface PaymentChannelProvider {
79+
PaymentChannel getChannelById(BigInteger channelId);
80+
}
81+
82+
class AskDaemonFirstPaymentChannelProvider
83+
PaymentChannelProvider <|.. AskDaemonFirstPaymentChannelProvider
84+
AskDaemonFirstPaymentChannelProvider *-- MultiPartyEscrowContract
85+
AskDaemonFirstPaymentChannelProvider *-- PaymentChannelStateService
86+
87+
class EscrowPayment
88+
Payment ()- EscrowPayment
89+
90+
}
91+
92+
package io.singularitynet.sdk.client {
93+
94+
interface Configuration {
95+
String getEthereumJsonRpcEndpoint();
96+
URL getIpfsUrl();
97+
SignerType getSignerType();
98+
String getSignerMnemonic();
99+
byte[] getSignerPrivateKey();
100+
}
101+
102+
class JsonConfiguration
103+
Configuration <|.. JsonConfiguration
104+
105+
interface DependencyFactory {
106+
Web3j getWeb3j();
107+
ContractGasProvider getContractGasProvider(Web3j web3j);
108+
IPFS getIpfs();
109+
Signer getSigner();
110+
}
111+
112+
class ConfigurationDependencyFactory
113+
DependencyFactory <|.. ConfigurationDependencyFactory
114+
115+
interface PaymentStrategy {
116+
<ReqT, RespT> Payment getPayment(GrpcCallParameters<ReqT, RespT> parameters, ServiceClient serviceClient);
117+
}
118+
119+
class FixedPaymentChannelPaymentStrategy
120+
PaymentStrategy <|.. FixedPaymentChannelPaymentStrategy
121+
122+
class Sdk {
123+
Sdk(Configuration config);
124+
Sdk(DependencyFactory factory);
125+
126+
ServiceClient newServiceClient(String orgId, String serviceId, String endpointGroupName, PaymentStrategy paymentStrategy);
127+
void shutdown();
128+
}
129+
Sdk -- Configuration
130+
Sdk -- ServiceClient
131+
Sdk -- DependencyFactory
132+
133+
interface ServiceClient {
134+
MetadataProvider getMetadataProvider();
135+
PaymentChannelProvider getPaymentChannelProvider();
136+
Signer getSigner();
137+
T getGrpcStub(Function<Channel, T> constructor);
138+
void shutdownNow();
139+
}
140+
141+
class BaseServiceClient
142+
ServiceClient <|.. BaseServiceClient
143+
BaseServiceClient *-- DaemonConnection
144+
BaseServiceClient *-- MetadataProvider
145+
BaseServiceClient *-- PaymentChannelProvider
146+
BaseServiceClient *-- PaymentStrategy
147+
BaseServiceClient *-- Signer
148+
149+
}
150+
151+
@enduml
152+

0 commit comments

Comments
 (0)