From 4557761d088c03dcc9b1a4e7a4120d330c311331 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 17 Sep 2021 10:00:21 -0700 Subject: [PATCH] Added pseudo code for next steps --- src/use-cases/offer.js | 27 ++++++-- test/unit/entities/offer.entity.unit.js | 87 ------------------------- 2 files changed, 23 insertions(+), 91 deletions(-) diff --git a/src/use-cases/offer.js b/src/use-cases/offer.js index ecbf7bb..62aa686 100644 --- a/src/use-cases/offer.js +++ b/src/use-cases/offer.js @@ -23,15 +23,23 @@ class OfferLib { try { // console.log('createOffer(entryObj): ', entryObj) + // Input Validation + const offerEntity = this.offerEntity.validate(entryObj) + // console.log('offerEntity: ', offerEntity) + + // Ensure sufficient tokens exist to create the offer. + // await this.ensureFunds(offerEntity) + + // Move the tokens to holding address. + // const utxoInfo = await moveTokens(offerEntity) + + // Update the offer with the new UTXO information. + // Burn PSF token to pay for P2WDB write. const txid = await this.adapters.wallet.burnPsf() console.log('burn txid: ', txid) console.log(`https://simpleledger.info/tx/${txid}`) - // Input Validation - const offerEntity = this.offerEntity.validate(entryObj) - // console.log('offerEntity: ', offerEntity) - // TODO: Move tokens to holding address, which will generate the UTXO to // use in the Offer. @@ -60,6 +68,17 @@ class OfferLib { throw err } } + + // Move the tokens indicated in the offer to a temporary holding address. + // This will generate the UTXO used in the Signal message. This function + // moves the funds and returns the UTXO information. + async moveTokens () { + try { + // + } catch (err) { + console.error('Error in moveTokens()') + } + } } module.exports = OfferLib diff --git a/test/unit/entities/offer.entity.unit.js b/test/unit/entities/offer.entity.unit.js index b808ce5..98f5d73 100644 --- a/test/unit/entities/offer.entity.unit.js +++ b/test/unit/entities/offer.entity.unit.js @@ -152,91 +152,4 @@ describe('#Offer-Entity', () => { } }) }) - - // describe('#validate', () => { - // it('should throw an error if entry is not provided', () => { - // try { - // uut.validate() - // } catch (err) { - // assert.include(err.message, "Property 'entry' must be a string!") - // } - // }) - // - // it('should throw an error if description is not provided', () => { - // try { - // const inputData = { - // entry: 'entry' - // } - // uut.validate(inputData) - // } catch (err) { - // assert.include(err.message, "Property 'description' must be a string!") - // } - // }) - // - // it('should throw an error if slpAddress is not provided', () => { - // try { - // const inputData = { - // entry: 'entry', - // description: 'test' - // } - // uut.validate(inputData) - // } catch (err) { - // assert.include(err.message, "Property 'slpAddress' must be a string!") - // } - // }) - // - // it('should throw an error if signature is not provided', () => { - // try { - // const inputData = { - // entry: 'entry', - // description: 'test', - // slpAddress: 'simpleledger:qpnty9t0w93fez04h7yzevujpv8pun204qqp0jfafg' - // } - // uut.validate(inputData) - // } catch (err) { - // assert.include(err.message, "Property 'signature' must be a string!") - // } - // }) - // it('should throw an error if category is not provided', () => { - // try { - // const inputData = { - // entry: 'entry', - // description: 'test', - // slpAddress: 'simpleledger:qpnty9t0w93fez04h7yzevujpv8pun204qqp0jfafg', - // signature: 'IFytRg6KpvTHCzcW0ZwVhPqdKtRGpoRDcuEb958yIgJFUJlb1F5qPzt/JnlYE7r012BSFj+UT67DZVTU8oNB5vw=' - // } - // uut.validate(inputData) - // } catch (err) { - // assert.include(err.message, "Property 'category' must be a string!") - // } - // }) - // - // it('should return a Entry object', () => { - // const inputData = { - // entry: 'entry', - // description: 'test', - // slpAddress: 'simpleledger:qpnty9t0w93fez04h7yzevujpv8pun204qqp0jfafg', - // signature: 'IFytRg6KpvTHCzcW0ZwVhPqdKtRGpoRDcuEb958yIgJFUJlb1F5qPzt/JnlYE7r012BSFj+UT67DZVTU8oNB5vw=', - // category: 'test' - // } - // - // const entry = uut.validate(inputData) - // // console.log('entry: ', entry) - // - // assert.property(entry, 'entry') - // assert.equal(entry.entry, inputData.entry) - // - // assert.property(entry, 'description') - // assert.equal(entry.description, inputData.description) - // - // assert.property(entry, 'slpAddress') - // assert.equal(entry.slpAddress, inputData.slpAddress) - // - // assert.property(entry, 'signature') - // assert.equal(entry.signature, inputData.signature) - // - // assert.property(entry, 'slpAddress') - // assert.equal(entry.category, inputData.category) - // }) - // }) })