OSDN Git Service

update the build-chain-transactions function.
[bytom/bytom-electron.git] / src / sdk / api / transactions.js
index 3106e61..d4197c6 100644 (file)
@@ -88,6 +88,21 @@ const transactionsAPI = (client) => {
       ).then(resp => checkForError(resp))
     },
 
+    buildChain: (builderBlock, cb) => {
+      const builder = new TransactionBuilder()
+
+      try {
+        builderBlock(builder)
+      } catch (err) {
+        return Promise.reject(err)
+      }
+
+      return shared.tryCallback(
+        client.request('/build-chain-transactions', builder),
+        cb
+      ).then(resp => checkForError(resp)).catch(errors  => {throw checkForError(errors)})
+    },
+
     buildBatch: (builderBlocks, cb) => {
       const builders = []
       for (let i in builderBlocks) {
@@ -113,9 +128,10 @@ const transactionsAPI = (client) => {
         cb
       ),
 
-    signBatch: (templates, cb) => finalizeBatch(templates)
-      // TODO: merge batch errors from finalizeBatch
-      .then(finalized => client.signer.signBatch(finalized.successes, cb)),
+    signBatch: (template, cb) => finalize(template)
+      .then(finalized => client.request('/sign-transactions', finalized ).then(resp => checkForError(resp)).catch(errors  => {throw checkForError(errors)}),
+        cb
+      ),
 
     submit: (signed, cb) => shared.tryCallback(
       client.request('/submit-transaction', {'raw_transaction': signed}).then(resp => checkForError(resp)),
@@ -123,8 +139,8 @@ const transactionsAPI = (client) => {
     ),
 
     submitBatch: (signed, cb) => shared.tryCallback(
-      client.request('/submit-transaction', {transactions: signed})
-            .then(resp => new shared.BatchResponse(resp)),
+      client.request('/submit-transactions', {'raw_transactions': signed}).then(resp => checkForError(resp))
+        .catch(errors  => {throw checkForError(errors)}),
       cb
     ),