Skip to content

Commit

Permalink
add telegram version command, add quizzes keysend service
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbosworth committed Jan 15, 2021
1 parent d550bd2 commit 005287e
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 251 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Versions

## Version 7.16.0

- `send`: Add support for sending a quiz to a recipient
- `telegram`: Add support for checking the current and latest version with `/version`
- `telegram`: Display interactive quizzes that are sent as KeySends
- `telegram`: Mark unconfirmed on-chain transactions as pending

## Version 7.15.3

- `send`: Fix error message when failing to send
- `telegram`: Avoid writing API key when key is already written

## Version 7.15.2

- `gateway`: Fix subscription closiing when web socket closes
- `gateway`: Fix subscription closing when web socket closes
- `send`: Fix `max_fee` setting

## Version 7.15.1
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ bos utxos
## HowTos:

- The `accounting` [command howto](https://yalls.org/articles/97d67df1-d721-417d-a6c0-11d793739be9:0965AC5E-56CD-4870-9041-E69616660E6F/bc71e6bf-f2aa-4bae-a3e8-b12e7be2284c)
- The `open` [command howto](https://satbase.org/bos-open/)

## Nodes

Expand Down
2 changes: 2 additions & 0 deletions bos
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ prog
.option('--no-color', 'Mute all colors')
.option('--node <name>', 'Node to send funds from')
.option('--out <pubkey_or_alias>', 'Route out through a specific peer')
.option('--quiz <answer>', 'Quiz answers, first answer correct', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
Expand All @@ -1302,6 +1303,7 @@ prog
is_dry_run: options.dryrun,
max_fee: options.maxFee,
message: options.message,
quiz_answers: flatten([options.quiz].filter(n => !!n)),
out_through: options.out,
},
responses.returnObject({logger, reject, resolve}));
Expand Down
25 changes: 25 additions & 0 deletions network/push_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ const coins = ['BTC', 'LTC'];
const fiats = ['EUR', 'USD'];
const {isArray} = Array;
const isPublicKey = n => /^[0-9A-F]{66}$/i.test(n);
const maxQuizLength = 10;
const rateAsTokens = rate => 1e8 / rate;
const sumOf = arr => arr.reduce((sum, n) => sum + n, Number());
const minQuiz = 2;
const minTokens = 1;
const networks = {btc: 'BTC', btctestnet: 'BTC', ltc: 'LTC'};
const quizStart = 80509;
const tokAsBigTok = tokens => !tokens ? undefined : (tokens / 1e8).toFixed(8);
const utf8AsHex = n => Buffer.from(n, 'utf8').toString('hex');

/** Push a payment to a destination
Expand All @@ -32,6 +36,7 @@ const tokAsBigTok = tokens => !tokens ? undefined : (tokens / 1e8).toFixed(8);
max_fee: <Maximum Fee Tokens Number>
[message]: <Message to Include With Payment String>
[out_through]: <Pay Out Through Peer String>
quiz_answers: [<Quiz Answer String>]
request: <Request Function>
}
*/
Expand Down Expand Up @@ -68,6 +73,22 @@ module.exports = (args, cbk) => {
return cbk([400, 'MultipleOutboundPeersNotSupported']);
}

if (!isArray(args.quiz_answers)) {
return cbk([400, 'ExpectedMultipleQuizAnswersToSend']);
}

if (!!args.quiz_answers.length && !args.message) {
return cbk([400, 'ExpectedQuizQuestionMessageToSendQuiz']);
}

if (!!args.quiz_answers.length && args.quiz_answers.length < minQuiz) {
return cbk([400, 'ExpectedMultipleQuizAnswersToSend']);
}

if (args.quiz_answers.length > maxQuizLength) {
return cbk([400, 'TooManyAnswersForQuiz', {max: maxQuizLength}]);
}

if (!args.request) {
return cbk([400, 'ExpectedRequestFunctionToPushPayment']);
}
Expand Down Expand Up @@ -271,6 +292,10 @@ module.exports = (args, cbk) => {
is_real_payment: true,
max_fee: args.max_fee,
message: args.message,
messages: args.quiz_answers.map((answer, i) => ({
type: (quizStart + i).toString(),
value: utf8AsHex(answer),
})),
out_through: getOutKey,
tokens: parseAmount.tokens,
},
Expand Down
Loading

0 comments on commit 005287e

Please sign in to comment.