OSDN Git Service

add a transaction.md file in doc
authorsuccessli <successli@outlook.com>
Fri, 1 Jun 2018 06:52:04 +0000 (14:52 +0800)
committersuccessli <successli@outlook.com>
Fri, 1 Jun 2018 06:52:04 +0000 (14:52 +0800)
README.md
doc/transactions.md [new file with mode: 0644]
pom.xml
src/main/java/io/bytom/http/Client.java

index 5c3bead..221b3b4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ at [Bytom wiki](https://github.com/Bytom/bytom/wiki/API-Reference)
 
 ## Basic Usage
 
-```
+```java
 public static Client generateClient() throws BytomException {
     String coreURL = Configuration.getValue("bytom.api.url");
     String accessToken = Configuration.getValue("client.access.token");
@@ -82,6 +82,8 @@ receiverAsset = builder.create(client);
 
 ## Issue asset
 
+For more transaction details, see [transactions](https://github.com/Bytom/java-sdk/blob/master/doc/transactions.md)
+
 ### Firstly build the transaction
 
 ```java
diff --git a/doc/transactions.md b/doc/transactions.md
new file mode 100644 (file)
index 0000000..59656fa
--- /dev/null
@@ -0,0 +1,60 @@
+## Creating transactions
+
+Creating a transaction consists of three steps:
+
+1. **Build transaction**: Define what the transaction is supposed to do: issue new units of an asset, spend assets held in an account, control assets with an account, etc.
+2. **Sign transaction**: Authorize the spending of assets or the issuance of new asset units using private keys.
+3. **Submit transaction**: Submit a complete, signed transaction to the blockchain, and propagate it to other cores on the network.
+
+### Build transaction
+
+Rather than forcing you to manipulate inputs, outputs and change directly, the Bytom Core API allows you to build transactions using a list of high-level **actions**.
+
+There are seven types of actions:
+
+| ACTION                                  | DESCRIPTION                                                  |
+| --------------------------------------- | ------------------------------------------------------------ |
+| Issue                                   | Issues new units of a specified asset.                       |
+| Spend from account                      | Spends units of a specified asset from a specified account. Automatically handles locating outputs with enough units, and the creation of change outputs. |
+| Spend an unspent output from an account | Spends an entire, specific unspent output in an account. Change must be handled manually, using other actions. |
+| Control with receiver                   | Receives units of an asset into a receiver, which contains a control program and supplementary payment information, such as an expiration date. Used when making a payment to an external party/account in another Bytom Core. |
+| Retire                                  | Retires units of a specified asset.                          |
+
+### Sign transaction
+
+In order for a transaction to be accepted into the blockchain, its inputs must contain valid signatures. For issuance inputs, the signature must correspond to public keys named in the issuance program. For spending inputs, the signature must correspond to the public keys named in the control programs of the outputs being spent.
+
+Transaction signing provides the blockchain with its security. Strong cryptography prevents everyone–even the operators of the blockchain network–from producing valid transaction signatures without the relevant private keys.
+
+### Submit transaction
+
+Once a transaction is balanced and all inputs are signed, it is considered valid and can be submitted to the blockchain. The local core will forward the transaction to the generator, which adds it to the blockchain and propagates it to other cores on the network. 
+
+The Chain Core API does not return a response until either the transaction has been added to the blockchain and indexed by the local core, or there was an error. This allows you to write your applications in a linear fashion. In general, if a submission responds with success, the rest of your application may proceed with the guarantee that the transaction has been committed to the blockchain.
+
+
+
+## Examples
+
+### Asset issuance
+
+```java
+Transaction.Template controlAddress = new Transaction.Builder()
+        .addAction(
+                new Transaction.Action.SpendFromAccount()
+                        .setAccountId(senderAccount.id)
+                        .setAssetId(senderAsset.id)
+                        .setAmount(300000000)
+        )
+        .addAction(
+                new Transaction.Action.ControlWithAddress()
+                        .setAddress(receiverAddress.address)
+                        .setAssetId(senderAsset.id)
+                        .setAmount(200000000)
+        ).build(client);
+
+Transaction.Template singer = new Transaction.SignerBuilder().sign(client, controlAddress, "123456");
+
+Transaction.SubmitResponse txs = Transaction.submit(client, singer);
+```
+
diff --git a/pom.xml b/pom.xml
index a945c45..41e3f92 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -6,12 +6,27 @@
 
     <groupId>io.bytom</groupId>
     <artifactId>bytom-sdk-java</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.0.1</version>
     <packaging>jar</packaging>
 
     <name>bytom-sdk-java</name>
     <!-- FIXME change it to the project's website -->
     <url>http://www.example.com</url>
+    <description>SDK for Bytom project in github.</description>
+
+    <licenses>
+        <license>
+            <name>Apache License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+            <distribution>repo</distribution>
+        </license>
+    </licenses>
+
+
+    <issueManagement>
+        <url>https://github.com/Bytom/bytom-java-sdk/issues</url>
+        <system>GitHub Issues</system>
+    </issueManagement>
 
     <developers>
         <developer>
                     <target>7</target>
                 </configuration>
             </plugin>
-            <plugin>
-                <artifactId>maven-assembly-plugin</artifactId>
-                <configuration>
-                    <!--这部分可有可无,加上的话则直接生成可运行jar包-->
-                    <!--<archive>-->
-                    <!--<manifest>-->
-                    <!--<mainClass>${exec.mainClass}</mainClass>-->
-                    <!--</manifest>-->
-                    <!--</archive>-->
-                    <descriptorRefs>
-                        <descriptorRef>jar-with-dependencies</descriptorRef>
-                    </descriptorRefs>
-                    <!-- mvn assembly:assembly -Dmaven.test.skip=true -->
-                    <!-- mvn javadoc:javadoc -->
-                </configuration>
-            </plugin>
+            <!-- mvn assembly:assembly -Dmaven.test.skip=true -->
+            <!-- mvn javadoc:javadoc -->
         </plugins>
         <resources>
             <resource>
index 2c0c571..2a3b59a 100644 (file)
@@ -6,6 +6,7 @@ import io.bytom.common.*;
 import io.bytom.exception.*;
 import com.google.gson.Gson;
 import com.squareup.okhttp.*;
+import org.apache.log4j.Logger;
 import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
 import org.bouncycastle.openssl.PEMKeyPair;
 import org.bouncycastle.openssl.PEMParser;
@@ -45,6 +46,8 @@ public class Client {
     private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
     private static String version = "dev"; // updated in the static initializer
 
+    public static Logger logger = Logger.getLogger(Client.class);
+
     private static class BuildProperties {
         public String version;
     }
@@ -69,6 +72,7 @@ public class Client {
         if (coreURL.endsWith("/")) {
             //split the last char "/"
             coreURL = coreURL.substring(0, coreURL.length()-1);
+            logger.info("check the coreURL is right.");
         }
 
         return new Client(coreURL, accessToken);