GetBalance() {
48 | var model = new RequestApiModel();
49 | model.setPublicKey("Fn2tJrj7TU73cqkwTzaSkbRypYK5xhWEKqrad3nEeBkX");
50 | model.setMethodApi("GetBalance");
51 | model.setNetworkAlias("MainNet");
52 |
53 | return SendRequest(model);
54 | }
55 |
56 | @RequestMapping(path = "transferToken", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
57 | public void TransferToken() {
58 |
59 | var privateKey = "ohPH5zghdzmRDxd978r7y6r8YFoTcKm1MgW2gzik3omCuZLysjwNjTd9hnGREFyQHqhShoU4ri7q748UgdwZpzA";
60 |
61 | var model = new RequestApiModel();
62 | model.setPublicKey("FeFjpcsfHErXPk5HkfVcwH6zYaRT2xNytDTeSjfuVywt");
63 | model.setReceiverPublicKey("DM79n9Lbvm3XhBf1LwyBHESaRmJEJez2YiL549ArcHDC");
64 | model.setTokenPublicKey("FY8J5uSb2D3qX3iwUSvcUSGvrBGAvsrXxKxMQdFfpdmm");
65 | model.setAmount(new BigDecimal(0.51));
66 | model.setMethodApi("TransferToken");
67 | model.setFee(new BigDecimal(0.1));
68 | model.setNeedPack(true);
69 |
70 | var res1 = SendRequest(model);
71 |
72 |
73 |
74 | var crypt = Ed25519.sign(res1.getBody().getDataResponse().getTransactionPackagedStr().getBytes(), privateKey.getBytes());
75 |
76 | }
77 |
78 | public void TransferCs() {
79 |
80 | }
81 |
82 | public void SmartDeploy() {
83 |
84 | }
85 |
86 | public void SmartMethodExecute() {
87 |
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/API/capi/src/main/java/com/credits/utils/Base58.java:
--------------------------------------------------------------------------------
1 | package com.credits.utils;
2 |
3 | import com.credits.utils.ConverterException;
4 |
5 | import java.util.Arrays;
6 |
7 | /**
8 | * Base58 encoder
9 | *
10 | * The basic idea of the encoding is to treat the data bytes as a large number represented using
11 | * base-256 digits, convert the number to be represented using base-58 digits, preserve the exact
12 | * number of leading zeros (which are otherwise lost during the mathematical operations on the
13 | * numbers), and finally represent the resulting base-58 digits as alphanumeric ASCII characters.
14 | */
15 | public class Base58 {
16 | public static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray();
17 | private static final char ENCODED_ZERO = ALPHABET[0];
18 | private static final int[] INDEXES = new int[128];
19 | static {
20 | Arrays.fill(INDEXES, -1);
21 | for (int i = 0; i < ALPHABET.length; i++) {
22 | INDEXES[ALPHABET[i]] = i;
23 | }
24 | }
25 |
26 | /**
27 | * Encodes the given bytes as a base58 string (no checksum is appended).
28 | *
29 | * @param input the bytes to encode
30 | * @return the base58-encoded string
31 | */
32 | public static String encode(byte[] input) {
33 | if (input.length == 0) {
34 | return "";
35 | }
36 | // Count leading zeros.
37 | int zeros = 0;
38 | while (zeros < input.length && input[zeros] == 0) {
39 | ++zeros;
40 | }
41 | // Convert base-256 digits to base-58 digits (plus conversion to ASCII characters)
42 | input = Arrays.copyOf(input, input.length); // since we modifyObject it in-place
43 | char[] encoded = new char[input.length * 2]; // upper bound
44 | int outputStart = encoded.length;
45 | for (int inputStart = zeros; inputStart < input.length; ) {
46 | encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)];
47 | if (input[inputStart] == 0) {
48 | ++inputStart; // optimization - skip leading zeros
49 | }
50 | }
51 | // Preserve exactly as many leading encoded zeros in output as there were leading zeros in input.
52 | while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) {
53 | ++outputStart;
54 | }
55 | while (--zeros >= 0) {
56 | encoded[--outputStart] = ENCODED_ZERO;
57 | }
58 | // Return encoded string (including encoded leading zeros).
59 | return new String(encoded, outputStart, encoded.length - outputStart);
60 | }
61 |
62 |
63 | /**
64 | * Decodes the given base58 string into the original data bytes.
65 | *
66 | * @param input the base58-encoded string to decode
67 | * @return the decoded data bytes
68 | */
69 | public static byte[] decode(String input) throws ConverterException {
70 | if (input.length() == 0) {
71 | return new byte[0];
72 | }
73 | // Convert the base58-encoded ASCII chars to a base58 byte sequence (base58 digits).
74 | byte[] input58 = new byte[input.length()];
75 | for (int i = 0; i < input.length(); ++i) {
76 | char c = input.charAt(i);
77 | int digit = c < 128 ? INDEXES[c] : -1;
78 | if (digit < 0) {
79 | throw new ConverterException("Given string id not a valid base58 string");
80 | }
81 | input58[i] = (byte) digit;
82 | }
83 | // Count leading zeros.
84 | int zeros = 0;
85 | while (zeros < input58.length && input58[zeros] == 0) {
86 | ++zeros;
87 | }
88 | // Convert base-58 digits to base-256 digits.
89 | byte[] decoded = new byte[input.length()];
90 | int outputStart = decoded.length;
91 | for (int inputStart = zeros; inputStart < input58.length; ) {
92 | decoded[--outputStart] = divmod(input58, inputStart, 58, 256);
93 | if (input58[inputStart] == 0) {
94 | ++inputStart; // optimization - skip leading zeros
95 | }
96 | }
97 | // Ignore extra leading zeroes that were added during the calculation.
98 | while (outputStart < decoded.length && decoded[outputStart] == 0) {
99 | ++outputStart;
100 | }
101 | // Return decoded data (including original number of leading zeros).
102 | return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length);
103 | }
104 |
105 | /**
106 | * Divides a number, represented as an array of bytes each containing a single digit
107 | * in the specified base, by the given divisor. The given number is modified in-place
108 | * to contain the quotient, and the return value is the remainder.
109 | *
110 | * @param number the number to divide
111 | * @param firstDigit the index within the array of the first non-zero digit
112 | * (this is used for optimization by skipping the leading zeros)
113 | * @param base the base in which the number's digits are represented (up to 256)
114 | * @param divisor the number to divide by (up to 256)
115 | * @return the remainder of the division operation
116 | */
117 | private static byte divmod(byte[] number, int firstDigit, int base, int divisor) {
118 | // this is just long division which accounts for the base of the input digits
119 | int remainder = 0;
120 | for (int i = firstDigit; i < number.length; i++) {
121 | int digit = (int) number[i] & 0xFF;
122 | int temp = remainder * base + digit;
123 | number[i] = (byte) (temp / divisor);
124 | remainder = temp % divisor;
125 | }
126 | return (byte) remainder;
127 | }
128 | }
--------------------------------------------------------------------------------
/API/capi/src/main/java/com/credits/utils/ConverterException.java:
--------------------------------------------------------------------------------
1 | package com.credits.utils;
2 |
3 |
4 | import com.credits.utils.CreditsException;
5 |
6 | /**
7 | * Created by Igor Goryunov on 19.10.2018
8 | */
9 | public class ConverterException extends CreditsException {
10 |
11 | public ConverterException(String errorMessage) {
12 | super(errorMessage);
13 | }
14 |
15 | public ConverterException(Exception e) {
16 | super(e);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/API/capi/src/main/java/com/credits/utils/CreditsException.java:
--------------------------------------------------------------------------------
1 | package com.credits.utils;
2 |
3 | /**
4 | * Created by Rustem.Saidaliyev on 27.03.2018.
5 | */
6 | public class CreditsException extends RuntimeException {
7 |
8 | public CreditsException(String errorMessage) {
9 | super(errorMessage);
10 | }
11 |
12 | public CreditsException(Exception e) {
13 | super(e);
14 | }
15 |
16 | public CreditsException(String errorMessage, Throwable e) {
17 | super(e);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/API/capi/src/main/java/com/credits/utils/CryptoException.java:
--------------------------------------------------------------------------------
1 | package com.credits.utils;
2 |
3 |
4 | import com.credits.utils.CreditsException;
5 |
6 | /**
7 | * Created by Rustem.Saidaliyev on 27.03.2018.
8 | */
9 | public class CryptoException extends CreditsException {
10 |
11 | public CryptoException(String errorMessage) {
12 | super(errorMessage);
13 | }
14 |
15 | public CryptoException(Exception e) {
16 | super(e);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/API/capi/src/main/java/com/credits/utils/Ed25519.java:
--------------------------------------------------------------------------------
1 | package com.credits.utils;
2 |
3 | import net.i2p.crypto.eddsa.EdDSAEngine;
4 | import net.i2p.crypto.eddsa.EdDSAPublicKey;
5 | import net.i2p.crypto.eddsa.KeyPairGenerator;
6 | import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
7 | import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
8 | import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import java.math.BigDecimal;
13 | import java.nio.charset.StandardCharsets;
14 | import java.security.InvalidKeyException;
15 | import java.security.KeyPair;
16 | import java.security.PrivateKey;
17 | import java.security.PublicKey;
18 | import java.security.SignatureException;
19 |
20 | /**
21 | * Утилита генерации публичных, приватных ключей, подписи
22 | * на базе ED25519
23 | *
24 | * Created by Rustem Saidaliyev on 14-Mar-18.
25 | */
26 | public class Ed25519 {
27 |
28 | private static final Logger LOGGER = LoggerFactory.getLogger(Ed25519.class);
29 |
30 | private static final KeyPairGenerator KEY_PAIR_GENERATOR = new KeyPairGenerator();
31 |
32 | public static final String ED_25519 = "Ed25519";
33 |
34 | public static KeyPair generateKeyPair() {
35 | synchronized (KEY_PAIR_GENERATOR) {
36 | return KEY_PAIR_GENERATOR.generateKeyPair();
37 | }
38 | }
39 |
40 | public static byte[] sign(byte[] data, PrivateKey privateKey) throws CryptoException {
41 |
42 | EdDSAEngine edDSAEngine = new EdDSAEngine();
43 | try {
44 | edDSAEngine.initSign(privateKey);
45 | return edDSAEngine.signOneShot(data);
46 | } catch (InvalidKeyException | SignatureException e) {
47 | throw new CryptoException(e);
48 | }
49 | }
50 |
51 | public static Boolean verify(byte[] data, byte[] signature, PublicKey publicKey) throws CryptoException {
52 |
53 | EdDSAEngine edDSAEngine = new EdDSAEngine();
54 | try {
55 | edDSAEngine.initVerify(publicKey);
56 | return edDSAEngine.verifyOneShot(data, signature);
57 | } catch (InvalidKeyException | SignatureException e) {
58 | throw new CryptoException(e);
59 | }
60 | }
61 |
62 | public static PublicKey bytesToPublicKey(byte[] bytes) {
63 | EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(ED_25519);
64 | EdDSAPublicKeySpec key = new EdDSAPublicKeySpec(bytes, spec);
65 | return new EdDSAPublicKey(key);
66 | }
67 |
68 | // public static PrivateKey bytesToPrivateKey(byte[] bytes) {
69 | //
70 | // byte[] seedByteArr = Utils.parseSubArray(bytes, 0, 32); // seed
71 | // EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(ED_25519);
72 | // EdDSAPrivateKeySpec key = new EdDSAPrivateKeySpec(seedByteArr, spec);
73 | // return new EdDSAPrivateKey(key);
74 | // }
75 |
76 | // public static String generateSignOfTransaction(String innerId, String source, String target, BigDecimal amount,
77 | // BigDecimal balance, byte currency, PrivateKey privateKey)
78 | // throws ConverterException, CryptoException {
79 | //
80 | // Amount amountValue = NodePojoConverter.bigDecimalToAmount(amount);
81 | //
82 | // Integer amountIntegral = amountValue.getIntegral();
83 | // Long amountFraction = amountValue.getFraction();
84 | //
85 | // Amount balanceValue = NodePojoConverter.bigDecimalToAmount(balance);
86 | //
87 | // Integer balanceIntegral = balanceValue.getIntegral();
88 | // Long balanceFraction = balanceValue.getFraction();
89 | //
90 | // String transaction =
91 | // String.format("%s|%s|%s|%s:%s|%s:%s|%s", innerId, source, target, GeneralConverter.toString(amountIntegral),
92 | // GeneralConverter.toString(amountFraction), GeneralConverter.toString(balanceIntegral),
93 | // GeneralConverter.toString(balanceFraction), currency);
94 | //
95 | // LOGGER.debug("Signing the message [{}]", transaction);
96 | // byte[] signature;
97 | // signature = Ed25519.sign(transaction.getBytes(StandardCharsets.US_ASCII), privateKey);
98 | //
99 | // return GeneralConverter.encodeToBASE58(signature);
100 | // }
101 | //
102 | // public static byte[] publicKeyToBytes(PublicKey publicKey) {
103 | // EdDSAPublicKey edDSAPublicKey = (EdDSAPublicKey) publicKey;
104 | // return edDSAPublicKey.getAbyte();
105 | // }
106 | //
107 | // public static byte[] privateKeyToBytes(PrivateKey privateKey) {
108 | // EdDSAPrivateKey edDSAPrivateKey = (EdDSAPrivateKey) privateKey;
109 | // return Utils.concatenateArrays(edDSAPrivateKey.getSeed(), edDSAPrivateKey.getAbyte());
110 | // }
111 | }
--------------------------------------------------------------------------------
/API/capi/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/API/capi/src/test/java/com/credits/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.credits;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class DemoApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Docker/Readme.md:
--------------------------------------------------------------------------------
1 | # Docker (Linux/Windows)
2 |
3 | ## credits_docker_mainnet
4 | Using Credits (version 4_2_410) in Docker
5 |
6 | ## credits_docker_testnet
7 | Using Credits (version 4.2.417) in Docker
8 |
9 |
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:18.04
2 |
3 | # update && java 11 install
4 | RUN apt-get update && \
5 | apt-get upgrade -y && \
6 | apt-get install -y software-properties-common && \
7 | add-apt-repository ppa:linuxuprising/java -y && \
8 | apt-get update && \
9 | echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | /usr/bin/debconf-set-selections && \
10 | apt-get install -y oracle-java11-installer && \
11 | apt-get install oracle-java11-set-default && \
12 | apt-get clean
13 | # setup worker dir
14 | WORKDIR /credits
15 | # copy all files from current dir to ./credits
16 | COPY /build /credits
17 | # ports
18 | EXPOSE 6000
19 | EXPOSE 9090
20 | # run
21 | CMD ["./runner", "--db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt"]
22 |
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/Readme.md:
--------------------------------------------------------------------------------
1 | # credits_docker_mainnet
2 |
3 | Using Credits (version 4_2_410) in Docker
4 | https://developers.credits.com/en/Articles/a_Using_Credits_blockchain_software_in_Docker
5 |
6 | ## How to build
7 |
8 | #### You can run build.sh or run step by step commands below:
9 | ```shell
10 | wget https://credits.com/Content/file_users/Credits_Network_for_Linux_x64_4_2_410.tar.gz -P build Credits_Network_for_Linux_x64_4_2_410.tar.gz
11 | tar -xvzf build/Credits_Network_for_Linux_x64_4_2_410.tar.gz --strip-components 1 -C build
12 | rm build/Credits_Network_for_Linux_x64_4_2_410.tar.gz
13 |
14 | g++ -pthread source/runner.cpp -o build/runner
15 | cp common/* build/
16 |
17 | sudo docker build -t credits_mainnet:4.2.410 .
18 | sudo docker volume create main_db
19 | sudo docker volume create main_keys
20 | ```
21 |
22 | ### some helpers
23 | ```shell
24 | sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
25 | ```
26 |
27 | ### run bash
28 | ```shell
29 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410 bash
30 | ```
31 |
32 | ### run local repo node
33 | ```shell
34 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410
35 | ```
36 |
37 | ### run node docker repo
38 | ```shell
39 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys pvl1175/credits_mainnet:4.2.410
40 | ```
41 |
42 | ### additional example
43 | ```shell
44 | ./client --db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt
45 | ```
46 |
47 | ## How to run
48 | ### You can run run.sh or run step by step commands below:
49 |
50 | ### run bash
51 | ```shell
52 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest bash
53 | ```
54 |
55 | ### run node
56 | ```shell
57 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest
58 | ```
59 |
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/build.sh:
--------------------------------------------------------------------------------
1 | wget https://credits.com/Content/file_users/Credits_Network_for_Linux_x64_4_2_410.tar.gz -P build Credits_Network_for_Linux_x64_4_2_410.tar.gz
2 | tar -xvzf build/Credits_Network_for_Linux_x64_4_2_410.tar.gz --strip-components 1 -C build
3 | rm build/Credits_Network_for_Linux_x64_4_2_410.tar.gz
4 |
5 | g++ -pthread source/runner.cpp -o build/runner
6 | cp common/* build/
7 |
8 | sudo docker build -t credits_mainnet:4.2.410 .
9 | sudo docker volume create main_db
10 | sudo docker volume create main_keys
11 |
12 | # some helpers
13 | #sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
14 |
15 | # run bash
16 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410 bash
17 |
18 | # run local repo node
19 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410
20 |
21 | # run node docker repo
22 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys pvl1175/credits_mainnet:4.2.410
23 |
24 | # additional example
25 | #./client --db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt
26 |
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/clean.sh:
--------------------------------------------------------------------------------
1 | rm -r -f build
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/common/clean_main_db.sh:
--------------------------------------------------------------------------------
1 | rm main_db/*
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/common/clean_main_keys.sh:
--------------------------------------------------------------------------------
1 | rm main_keys/*
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/common/run.sh:
--------------------------------------------------------------------------------
1 | ./runner "--db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt"
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/run.sh:
--------------------------------------------------------------------------------
1 | # run bash
2 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest bash
3 |
4 | # run node
5 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest
6 |
--------------------------------------------------------------------------------
/Docker/credits_docker_mainnet/source/runner.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | void run_contract_executor()
8 | {
9 | system("java -jar contract-executor.jar");
10 | }
11 |
12 | void run_node(char* params)
13 | {
14 | ostringstream ss;
15 | ss << "./client " << params;
16 | system(ss.str().c_str());
17 | }
18 |
19 | int main(int argc, char* argv[])
20 | {
21 | if(argc != 2)
22 | {
23 | cout << "Usage: ./runner \"parameters\"" << endl;
24 | cout << "For example: ./runner \"--db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt\"" << endl;
25 | return 1;
26 | }
27 |
28 | thread th1(run_contract_executor);
29 | thread th2(run_node, ref(argv[1]));
30 |
31 | th1.join();
32 | th2.join();
33 | }
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:18.04
2 |
3 | # update && java 11 install
4 | RUN apt-get update && \
5 | apt-get upgrade -y && \
6 | apt-get install -y software-properties-common && \
7 | add-apt-repository ppa:linuxuprising/java -y && \
8 | apt-get update && \
9 | echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | /usr/bin/debconf-set-selections && \
10 | apt-get install -y oracle-java11-installer && \
11 | apt-get install oracle-java11-set-default && \
12 | apt-get clean
13 | # setup worker dir
14 | WORKDIR /credits
15 | # copy all files from current dir to ./credits
16 | COPY /build /credits
17 | # ports
18 | EXPOSE 6000
19 | EXPOSE 9090
20 | # run
21 | CMD ["./runner", "--db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt"]
22 |
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/Readme.md:
--------------------------------------------------------------------------------
1 | # credits_docker_testnet
2 | Using Credits (version 4.2.417) in Docker
3 | https://developers.credits.com/en/Articles/a_Using_Credits_blockchain_software_in_Docker
4 |
5 | ## How to build
6 | ### You can run build.sh or run step by step commands below:
7 | ```shell
8 | wget https://credits.com/Content/file_users/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz -P build Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz
9 | tar -xvzf build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz --strip-components 1 -C build
10 | rm build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz
11 |
12 | g++ -pthread source/runner.cpp -o build/runner
13 | cp common/* build/
14 |
15 | sudo docker build -t credits_testnet:4.2.417 .
16 | sudo docker volume create test_db
17 | sudo docker volume create test_keys
18 | ```
19 | ### some helpers
20 | ```shell
21 | sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
22 | ```
23 | ### run bash
24 | ```shell
25 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417 bash
26 | ```
27 | ### run local repo node
28 | ```shell
29 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417
30 | ```
31 | ### run node docker repo
32 | ```shell
33 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys pvl1175/credits_testnet:4.2.417
34 | ```
35 | ### additional example
36 | ```shell
37 | ./client --db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt
38 | ```
39 |
40 | ## How to run
41 | ### You can run run.sh or run step by step commands below:
42 | ### run bash
43 | ```shell
44 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest bash
45 | ```
46 | ### run node
47 | ```shell
48 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest
49 | ```
50 |
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/build.sh:
--------------------------------------------------------------------------------
1 | wget https://credits.com/Content/file_users/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz -P build Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz
2 | tar -xvzf build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz --strip-components 1 -C build
3 | rm build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz
4 |
5 | g++ -pthread source/runner.cpp -o build/runner
6 | cp common/* build/
7 |
8 | sudo docker build -t credits_testnet:4.2.417 .
9 | sudo docker volume create test_db
10 | sudo docker volume create test_keys
11 |
12 | # some helpers
13 | #sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
14 |
15 | # run bash
16 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417 bash
17 |
18 | # run local repo node
19 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417
20 |
21 | # run node docker repo
22 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys pvl1175/credits_testnet:4.2.417
23 | # additional example
24 | #./client --db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt
25 |
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/clean.sh:
--------------------------------------------------------------------------------
1 | rm -r -f build
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/common/clean_test_db.sh:
--------------------------------------------------------------------------------
1 | rm test_db/*
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/common/clean_test_keys.sh:
--------------------------------------------------------------------------------
1 | rm test_keys/*
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/common/run.sh:
--------------------------------------------------------------------------------
1 | ./runner "--db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt"
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/run.sh:
--------------------------------------------------------------------------------
1 | # run bash
2 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest bash
3 |
4 | # run node
5 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest
6 |
--------------------------------------------------------------------------------
/Docker/credits_docker_testnet/source/runner.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | void run_contract_executor()
8 | {
9 | system("java -jar contract-executor.jar");
10 | }
11 |
12 | void run_node(char* params)
13 | {
14 | ostringstream ss;
15 | ss << "./client " << params;
16 | system(ss.str().c_str());
17 | }
18 |
19 | int main(int argc, char* argv[])
20 | {
21 | if(argc != 2)
22 | {
23 | cout << "Usage: ./runner \"parameters\"" << endl;
24 | cout << "For example: ./runner \"--db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt\"" << endl;
25 | return 1;
26 | }
27 |
28 | thread th1(run_contract_executor);
29 | thread th2(run_node, ref(argv[1]));
30 |
31 | th1.join();
32 | th2.join();
33 | }
34 |
35 |
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # API (Linux/Windows)
2 |
3 | ## CreditsCPlusPlusDemoCMake
4 |
5 | A simple console C++ (CMake) application
6 | Using the public key of the wallet displays the balance.
7 |
8 | ## CreditsCSharpDemo
9 | A simple console C# (.NET Core) application.
10 | Using the public key of the wallet displays the balance.
11 | Allows to create a transaction (transfer coins from the current wallet to the specified one) and execute it.
12 |
13 | ## CreditsJSDemo
14 | A simple console JS application
15 | Using the public key of the wallet displays the balance.
16 |
17 | ## CreditsPythonApiDemo
18 | A simple console Python application
19 | Using the public key of the wallet displays the balance.
20 |
21 |
22 | # Docker (Linux/Windows)
23 |
24 | ## credits_docker_mainnet
25 | Using Credits (version 4_2_410) in Docker
26 |
27 | ## credits_docker_testnet
28 | Using Credits (version 4.2.412.3) in Docker
29 |
30 |
31 | # Utils (Linux/Windows)
32 |
33 | ## cr-dev-book-windows
34 | A simple Electron application, showing the contents of the Credits Developer Portal https://developers.credits.com/
35 |
36 | ## cr-monitor-windows
37 | A simple Electron application, showing the contents of the Credits Monitor
38 |
39 | ## cr-web-wallet-windows
40 | A simple Electron application, showing the contents of the Credits Web Wallet
41 |
--------------------------------------------------------------------------------
/SmartContracts/Readme.md:
--------------------------------------------------------------------------------
1 | # CS smart-contracts (examples)
2 |
--------------------------------------------------------------------------------
/SmartContracts/sm_tracking the movement/Readme.md:
--------------------------------------------------------------------------------
1 | # Tracking the movement of ordered goods
2 |
3 | ## Our user class
4 | ### The user class must inherit from Serializable
5 | ```shell
6 | public static class Geo implements Serializable {
7 | private final int productId;
8 | private final String latitude;
9 | private final String longitude;
10 | public Geo(int productId, String latitude, String longitude) {
11 | this.productId = productId;
12 | this.latitude = latitude;
13 | this.longitude = longitude;
14 | }
15 | }
16 | ```
17 |
18 | ### The custom list declaration
19 | ```shell
20 | private final ArrayList geoList;
21 | ```
22 |
23 | ### Creating the list in the constructor
24 | ```shell
25 | public Contract() {
26 | geoList = new ArrayList<>();
27 | }
28 | ```
29 |
30 | ### Adding the geo position of our product
31 | ```shell
32 | public void saveGeo(int productId, String latitude, String longitude){
33 | geoList.add(new Geo(productId, latitude, longitude));
34 | }
35 | ```
36 |
37 | ### Getting our user list
38 | ```shell
39 | public ArrayList loadGeo(){
40 | return geoList;
41 | }
42 | ```
43 |
44 | ### Getting the count of our user list
45 | ```shell
46 | public int geoListSize(){
47 | return geoList.size();
48 | }
49 | ```
50 |
--------------------------------------------------------------------------------
/SmartContracts/sm_tracking the movement/sm_tracking the movement.java:
--------------------------------------------------------------------------------
1 | import com.credits.scapi.v0.SmartContract;
2 | import java.io.Serializable;
3 | import java.util.ArrayList;
4 |
5 | public class Contract extends SmartContract {
6 | private final ArrayList geoList;
7 |
8 | public Contract() {
9 | geoList = new ArrayList<>();
10 | }
11 |
12 | public void saveGeo(int productId, String latitude, String longitude){
13 | geoList.add(new Geo(productId, latitude, longitude));
14 | }
15 |
16 | public ArrayList loadGeo(){
17 | return geoList;
18 | }
19 |
20 | public int geoListSize(){
21 | return geoList.size();
22 | }
23 |
24 | public static class Geo implements Serializable {
25 | private final int productId;
26 | private final String latitude;
27 | private final String longitude;
28 |
29 | public Geo(int productId, String latitude, String longitude) {
30 | this.productId = productId;
31 | this.latitude = latitude;
32 | this.longitude = longitude;
33 | }
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Utils/Readme.md:
--------------------------------------------------------------------------------
1 | # Utils (Linux/Windows)
2 |
3 | ## cr-dev-book-windows
4 | A simple Electron application, showing the contents of the Credits Developer Portal https://developers.credits.com/
5 |
6 | ## cr-monitor-windows
7 | A simple Electron application, showing the contents of the Credits Monitor
8 |
9 | ## cr-web-wallet-windows
10 | A simple Electron application, showing the contents of the Credits Web Wallet
11 |
--------------------------------------------------------------------------------
/Utils/cr-dev-book-windows/Readme.md:
--------------------------------------------------------------------------------
1 | # cr-dev-book-windows
2 | A simple Electron application, showing the contents of the Credits Developer Portal
3 | https://developers.credits.com/
--------------------------------------------------------------------------------
/Utils/cr-dev-book-windows/index.js:
--------------------------------------------------------------------------------
1 | const { app, BrowserWindow } = require('electron');
2 |
3 | let win = null;
4 |
5 | const appUrl = `https://developers.credits.com/`;
6 |
7 | function createElectronShell() {
8 | win = new BrowserWindow(
9 | {
10 | width: 1200,
11 | height: 900,
12 | webPreferences: {
13 | plugins: true,
14 | nodeIntegration: false,
15 | webSecurity: false,
16 | allowDisplayingInsecureContent: true,
17 | allowRunningInsecureContent: true
18 | }
19 | }
20 | );
21 |
22 | win.setMenu(null);
23 | win.loadURL(appUrl);
24 | win.on('closed', () => {
25 | win = null
26 | });
27 | }
28 |
29 | app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
30 |
31 | app.on('ready', createElectronShell);
32 |
33 | app.on('browser-window-created',function(e,window) {
34 | window.setMenu(null);
35 | });
36 |
37 | app.on('window-all-closed', () => {
38 | if (process.platform !== 'darwin') app.quit();
39 | });
40 |
41 | app.on('activate', () => {
42 | if (win == null) createElectronShell();
43 | });
--------------------------------------------------------------------------------
/Utils/cr-dev-book-windows/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cr-dev-book",
3 | "version": "1.0.0",
4 | "description": "CREDITS Dev Book",
5 | "main": "index.js",
6 | "homepage": "credits.com",
7 | "author": "pvl1175 ",
8 | "license": "ISC",
9 | "build": {
10 | "appId": "com.credits.dev-book",
11 | "productName": "CREDITS Dev Book",
12 | "win": {
13 | "target": [
14 | "nsis"
15 | ]
16 | },
17 | "nsis": {
18 | "runAfterFinish": true
19 | }
20 | },
21 | "scripts": {
22 | "pack": "build --dir",
23 | "dist": "build",
24 | "postinstall": "install-app-deps",
25 | "start": "electron ."
26 | },
27 | "devDependencies": {
28 | "electron": "^1.8.8",
29 | "electron-builder": "^20.38.3"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Utils/cr-monitor-windows/Readme.md:
--------------------------------------------------------------------------------
1 | # cr-monitor-windows
2 | A simple Electron application, showing the contents of the Credits Monitor
3 |
--------------------------------------------------------------------------------
/Utils/cr-monitor-windows/index.js:
--------------------------------------------------------------------------------
1 | const { app, BrowserWindow } = require('electron');
2 |
3 | let win = null;
4 |
5 | const appUrl = `http://monitor.credits.com/`;
6 |
7 | function createElectronShell() {
8 | win = new BrowserWindow(
9 | {
10 | width: 1000,
11 | height: 900,
12 | webPreferences: {
13 | plugins: true,
14 | nodeIntegration: false,
15 | webSecurity: false,
16 | allowDisplayingInsecureContent: true,
17 | allowRunningInsecureContent: true
18 | }
19 | }
20 | );
21 |
22 | win.setMenu(null);
23 | win.loadURL(appUrl);
24 | win.on('closed', () => {
25 | win = null
26 | });
27 | }
28 |
29 | app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
30 |
31 | app.on('ready', createElectronShell);
32 |
33 | app.on('browser-window-created',function(e,window) {
34 | window.setMenu(null);
35 | });
36 |
37 | app.on('window-all-closed', () => {
38 | if (process.platform !== 'darwin') app.quit();
39 | });
40 |
41 | app.on('activate', () => {
42 | if (win == null) createElectronShell();
43 | });
--------------------------------------------------------------------------------
/Utils/cr-monitor-windows/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cr-web-monitor",
3 | "version": "1.0.0",
4 | "description": "CREDITS Monitor",
5 | "main": "index.js",
6 | "homepage": "credits.com",
7 | "author": "pvl1175 ",
8 | "license": "ISC",
9 | "build": {
10 | "appId": "com.credits.monitor",
11 | "productName": "CREDITS Monitor",
12 | "win": {
13 | "target": [
14 | "nsis"
15 | ]
16 | },
17 | "nsis": {
18 | "runAfterFinish": true
19 | }
20 | },
21 | "scripts": {
22 | "pack": "build --dir",
23 | "dist": "build",
24 | "postinstall": "install-app-deps",
25 | "start": "electron ."
26 | },
27 | "devDependencies": {
28 | "electron": "^1.8.8",
29 | "electron-builder": "18.0.1"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Utils/cr-web-wallet-windows/Readme.md:
--------------------------------------------------------------------------------
1 | # cr-web-wallet-windows
2 | A simple Electron application, showing the contents of the Credits Web Wallet
3 |
--------------------------------------------------------------------------------
/Utils/cr-web-wallet-windows/index.js:
--------------------------------------------------------------------------------
1 | const { app, BrowserWindow } = require('electron');
2 |
3 | let win = null;
4 |
5 | const appUrl = `http://wallet.credits.com/`;
6 |
7 | function createElectronShell() {
8 | win = new BrowserWindow(
9 | {
10 | width: 1000,
11 | height: 900,
12 | webPreferences: {
13 | plugins: true,
14 | nodeIntegration: false,
15 | webSecurity: false,
16 | allowDisplayingInsecureContent: true,
17 | allowRunningInsecureContent: true
18 | }
19 | }
20 | );
21 |
22 | win.setMenu(null);
23 | win.loadURL(appUrl);
24 | win.on('closed', () => {
25 | win = null
26 | });
27 | }
28 |
29 | app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
30 |
31 | app.on('ready', createElectronShell);
32 |
33 | app.on('browser-window-created',function(e,window) {
34 | window.setMenu(null);
35 | });
36 |
37 | app.on('window-all-closed', () => {
38 | if (process.platform !== 'darwin') app.quit();
39 | });
40 |
41 | app.on('activate', () => {
42 | if (win == null) createElectronShell();
43 | });
--------------------------------------------------------------------------------
/Utils/cr-web-wallet-windows/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cr-web-wallet",
3 | "version": "1.0.0",
4 | "description": "CREDITS Web Wallet",
5 | "main": "index.js",
6 | "homepage": "credits.com",
7 | "author": "pvl1175 ",
8 | "license": "ISC",
9 | "build": {
10 | "appId": "com.credits.web-wallet",
11 | "productName": "CREDITS Web Wallet",
12 | "win": {
13 | "target": [
14 | "nsis"
15 | ]
16 | },
17 | "nsis": {
18 | "runAfterFinish": true
19 | }
20 | },
21 | "scripts": {
22 | "pack": "build --dir",
23 | "dist": "build",
24 | "postinstall": "install-app-deps",
25 | "start": "electron ."
26 | },
27 | "devDependencies": {
28 | "electron": "^1.8.8",
29 | "electron-builder": "18.0.1"
30 | },
31 | "dependencies": {
32 | "dist": "^0.1.2",
33 | "run": "^1.4.0"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------