Created
January 27, 2017 15:35
-
-
Save acastellana/17844d86d0f71b0ae18cc48029b66b0f to your computer and use it in GitHub Desktop.
sendMosaic(recipient, namespaceId, mosaics, amount, common, options)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* REQUIRES: | |
* - https://gist.github.com/acastellana/995326e3a41b5f690db50a17153af312 | |
* - https://gist.github.com/acastellana/607a47838e842417d80622568543eb74 | |
*/ | |
/** | |
* sendMosaic(recipient, namespaceId, mosaics, amount, common, options) Sends a minimal transaction containing a mosaic and optionally a message and some xem | |
* | |
* @param {object} recipient - Transaction receiver's account | |
* @param {string} namespaceId - Mosaic's namespace name | |
* @param {string} mosaic - Mosaic's name | |
* @param {integer} amount - Amount of mosaics to transfer | |
* @param {object} common - password/privateKey object | |
* @param {object} options - An object that can contain: options.xem and options.message | |
* | |
* @return {promise} - An announce transaction promise of the NetworkRequests service | |
*/ | |
sendMosaic(recipient, namespaceId, mosaics, amount, common, options) { | |
var xem = "" | |
var message = "" | |
if(options.xem) xem = options.xem; | |
if(options.message) message = options.message; | |
var transferData = {} | |
// Check that the recipient is a valid account and process it's public key | |
transferData.recipient = recipient; | |
this.processTxData(transferData); | |
// transferData.recipientPubKey is set now | |
// In case of mosaic transfer amount is used as multiplier, set to 1 as default | |
transferData.amount = 1; | |
// Other necessary | |
transferData.message = message; | |
transferData.encryptMessage = false; | |
// Setup mosaics information | |
transferData.mosaics = [{ | |
'mosaicId': { | |
'namespaceId': namespaceId, | |
'name': mosaics | |
}, | |
'quantity': amount, | |
}]; | |
if(xem > 0){ | |
transferData.mosaics[1] = { | |
'mosaicId': { | |
'namespaceId': "nem", | |
'name': 'xem' | |
}, | |
'quantity': xem, | |
} | |
} | |
// Build the entity to send | |
let entity = this._Transactions.prepareTransfer(common, transferData, this.mosaicsMetaData); | |
return this.send(entity, common); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment