Methods of sending a transaction

void sendTransaction(String source, String target, Double amount, String currency)

- The function of sending transactions. source — wallet address from which the transaction is being sent, target — wallet address to which transaction is being sent, amount — amount of sending values, currency — currency of transaction.

Example of using:

Send transaction from the wallet with sourse_wallet address (current wallet you are logged in) to the wallet with target_wallet address with amount 150.9 units in CS currency (system currency).

Method of getting balance

double getBalance(String address, String currency)

- The function for getting balance of the wallet. address — wallet address, currency — currency of balance.  

Example of using:

Line 5 — create local variable with double type for storing and further usage of balance sum. Line 6 — call a method for getting balance of the wallet with address some_wallet_address in CS currency and write resulting value in variable balance. Use the value we got, e.g. (line 7) display the value on the screen. The result of execution is available for view in application console CSSMARTCONTRACTS.

Example of ready contract:

Line 1-2 — connect java classes which are necessary for executing.

Line 5 — create variable and write in it value of system currency (CS) for further usage.

Line 6 — create variable checkedAccounts for writing the list of wallet addresses.

Lines 7-10 — create variable addresses and write the list of addresses we are going to use.

Line 13 — create variable totalSum for writing total balance.

Line 15-19 — with method getBalance check balances of the wallets written in variable addresses, if the balance is equal or more than 5.0 add address of this wallet in the list of variable checkedAccounts.

Line 21-23 — with method getBalance summarize balances of the wallets according to the list from checkedAccounts and write the result in variable totalSum. Assign the variable total to the value defining starting token balance.

import java.util.ArrayList;

import java.util.List;

public class Contract extends SmartContract {

     private String currency = "cs";

     private List<String> checkedAccounts = new ArrayList<>();

     private String[] addresses = new

String[]{"GbgvtDyAAMsfvvyFwbvdzNewoJWXTENxE1AwAFdXi7VJ",

     "9T56e8cyD8nsWqV8DXFubSinCYzjkQT7iAX2fa6KVtQt",

     "2W592kXR2wf4ghY4c5UXPvpWDAJycXHeKwWP6bChvcya",

     "2Jm6oznFqwS7kJURh2rAPNZHXah3vMj9ECTYtWop2sxS"};

public Contract() {

     double totalSum = 0;

     for (int i = 0; i < addresses.length; i++) {

        if (getBalance(addresses[i], currency) >= 5.0) {

        checkedAccounts.add(addresses[i]);

        }

    }

    for (int i = 0; i < checkedAccounts.size(); i++) {

        totalSum += getBalance(checkedAccounts.get(i), currency);

    }

    total = totalSum;

}

}