本文整理汇总了TypeScript中jQuery.Deferred类的典型用法代码示例。如果您正苦于以下问题:TypeScript Deferred类的具体用法?TypeScript Deferred怎么用?TypeScript Deferred使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Deferred类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: sendPayment
/**
* create a new transaction
* @param {Object} payment - the details of the transaction
* @param {string} payment.to - address to which transaction is sent to
* @param {number} payment.amount - number of zils sent
* @param {number} payment.gasPrice - gas price for this transaction
* @param {number} payment.gasLimit - gas limit for this transaction
* @returns {Promise} Promise object containing the newly created transaction id
*/
sendPayment(payment: any): Promise<any> {
this.startLoading()
var deferred = new $.Deferred()
let pubKey = secp256k1.publicKeyCreate(new Buffer(this.userWallet.privateKey, 'hex'), true)
let txn = {
version: 0,
nonce: this.userWallet.nonce + 1,
to: payment.address,
amount: payment.amount,
pubKey: pubKey.toString('hex'),
gasPrice: payment.gasPrice,
gasLimit: payment.gasLimit
}
var msg = this.intToByteArray(txn.version, 8).join('') +
this.intToByteArray(txn.nonce, 64).join('') +
txn.to +
txn.pubKey +
this.intToByteArray(txn.amount, 64).join('')
let sig = this.zlib.schnorr.sign(new Buffer(msg, 'hex'), new Buffer(this.userWallet.privateKey, 'hex'), pubKey)
let r = sig.r.toString('hex')
let s = sig.s.toString('hex')
while (r.length < 64) {
r = '0' + r
}
while (s.length < 64) {
s = '0' + s
}
txn['signature'] = r + s
let that = this
this.node.createTransaction(txn, function(err, data) {
if (err || data.error) {
deferred.reject(err)
} else {
deferred.resolve({
txId: data.result
})
}
that.endLoading()
})
return deferred.promise()
}
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:56,代码来源:zilliqa.service.ts
示例2: generateWalletJson
/**
* create a keystore json (wallet file) for an account containing the encrypted private key
* @param {string} passphrase - the passphrase to be used to encrypt the wallet
* @returns {string} string of the keystore json
*/
generateWalletJson(passphrase) {
var deferred = new $.Deferred()
var that = this
let privateKey = new Buffer(this.userWallet.privateKey, 'hex')
let address = this.userWallet.address
let salt = randomBytes(32);
let iv = randomBytes(16);
// key derivation function used is scrypt along with standard params
scryptAsync(passphrase, salt, {N: 262144, r: 1, p: 8, dkLen: 32}, function(derivedKey) {
derivedKey = new Buffer(derivedKey)
// ciphertext is private key encrypted with aes-128-ctr
let aesctr = new aesjs.ModeOfOperation.ctr(derivedKey.slice(0, 16), new aesjs.Counter(iv))
let ciphertext = aesctr.encrypt(privateKey)
var result = {
address: address,
crypto: {
cipher: "aes-128-ctr",
cipherparams: {
iv: iv.toString('hex'),
},
ciphertext: new Buffer(ciphertext).toString('hex'),
kdf: "scrypt",
kdfparams: {
dklen: 32,
n: 262144,
r: 1,
p: 8,
salt: salt.toString('hex'),
},
mac: sha3.digest(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext)])).toString('hex'),
},
id: uuid.v4({random: randomBytes(16)}),
version: 3,
}
deferred.resolve({
result: JSON.stringify(result)
})
})
return deferred.promise()
}
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:52,代码来源:zilliqa.service.ts
示例3: getInitData
/**
* fetch miscellaneous data like networkId/latest Tx blocknum
* @returns {Promise} Promise object containing the required data
*/
getInitData(): Promise<any> {
var deferred = new $.Deferred();
var that = this;
that.node.getNetworkId(function(err, data1) {
if (err || !data1.result) {
deferred.reject(err)
} else {
that.node.getLatestTxBlock(function(err, data2) {
if (err || !data2.result) {
deferred.reject(err)
} else {
deferred.resolve({
networkId: data1.result,
latestTxBlock: data2.result.header.BlockNum
})
}
})
}
})
return deferred.promise();
}
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:27,代码来源:zilliqa.service.ts
示例4: refreshBalance
/**
* get the account details of an account using its public address
* @param {string} address - the public address of the account
* @returns {Promise} Promise object containing address, balance and nonce of the account
*/
refreshBalance(): Promise<any> {
var deferred = new $.Deferred()
let that = this
this.node.getBalance({address: this.userWallet.address}, function(err, data) {
if (err || data.error) {
deferred.reject({error: err})
} else {
let newUserWallet = {
address: that.userWallet.address,
balance: data.result.balance,
nonce: data.result.nonce,
privateKey: that.userWallet.privateKey
}
that.userWallet = newUserWallet
deferred.resolve({
result: true
})
}
})
return deferred.promise()
}
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:29,代码来源:zilliqa.service.ts
示例5:
that.node.getLatestTxBlock(function(err, data2) {
if (err || !data2.result) {
deferred.reject(err)
} else {
deferred.resolve({
networkId: data1.result,
latestTxBlock: data2.result.header.BlockNum
})
}
})
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:10,代码来源:zilliqa.service.ts
示例6: function
this.node.createTransaction(txn, function(err, data) {
if (err || data.error) {
deferred.reject(err)
} else {
deferred.resolve({
txId: data.result
})
}
that.endLoading()
})
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:10,代码来源:zilliqa.service.ts
示例7: scryptAsync
scryptAsync(passphrase, salt, {N: 262144, r: 1, p: 8, dkLen: 32}, function(derivedKey) {
derivedKey = new Buffer(derivedKey)
// ciphertext is private key encrypted with aes-128-ctr
let aesctr = new aesjs.ModeOfOperation.ctr(derivedKey.slice(0, 16), new aesjs.Counter(iv))
let ciphertext = aesctr.encrypt(privateKey)
var result = {
address: address,
crypto: {
cipher: "aes-128-ctr",
cipherparams: {
iv: iv.toString('hex'),
},
ciphertext: new Buffer(ciphertext).toString('hex'),
kdf: "scrypt",
kdfparams: {
dklen: 32,
n: 262144,
r: 1,
p: 8,
salt: salt.toString('hex'),
},
mac: sha3.digest(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext)])).toString('hex'),
},
id: uuid.v4({random: randomBytes(16)}),
version: 3,
}
deferred.resolve({
result: JSON.stringify(result)
})
})
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:33,代码来源:zilliqa.service.ts
注:本文中的jQuery.Deferred类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论