X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fsdk%2Fapi%2Ftransactions.js;fp=src%2Fsdk%2Fapi%2Ftransactions.js;h=d4197c60b696e7eb8c73e6074cf77530b3a00ba9;hb=b071eab41b24460cafff3824ec2825f3ef14951b;hp=3106e61a02c3e7091cfa55f9cddb23150404f900;hpb=f2694c383d322737b15ee805e0f1096bceabe9ae;p=bytom%2Fbytom-electron.git diff --git a/src/sdk/api/transactions.js b/src/sdk/api/transactions.js index 3106e61..d4197c6 100644 --- a/src/sdk/api/transactions.js +++ b/src/sdk/api/transactions.js @@ -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 ),