Git Product home page Git Product logo

payment-encoder's Introduction

Payment-Encoder

Build Status Coverage Status npm version npm version

js-standard-style

Payment-Encoder provides the encode/decode functions between a Colored Coins payment Object to buffer

Installation

$ npm install cc-payment-encoder

Encode

Params:

  • paymentObject - A standard Colored Coins payment object with the following properties:
{
  // Skip input after reading asset
  skip: "Boolean"

  // Range or fixed value output
  range: "Boolean"

  // percent or fixed amount
  percent: "Boolean"

  // Output to send asset to - max value is 15 if range is false and 8191 if true
  output: "Number"

  // Total amount of units to send
  amountOfUnits: "Number"
}

Returns a new Buffer holding the encoded payment.

Example:
var paymentEncode = require('cc-payment-encoder')
var paymentObject = {
    skip: false,
    range: false,
    percent: true,
    output: 1,
    amountOfUnits: 321321321
}

var code = paymentEncode.encode(paymentObject)

console.log(code) // Will print: <Buffer 21 80 99 37 cb 48>

Decode

Params:

  • consume - takes a consumable buffer (You can use buffer-consumer like in the example to create one)

Returns a Colored Coins payment Object

Example:
var paymentEncode = require('cc-payment-encoder')
var consumer = require('buffer-consumer')

var decode = paymentEncode.decode(consumer(code))
var codeBuffer = new Buffer([0x82,0x76,0x0e,0x1b,0x48])

console.log(paymentEncode.decode(consumer(codeBuffer)))
// Will print:
// {
//  skip: false,
//  range: false,
//  percent: true,
//  output: 1,
//  amountOfUnits: 321321321
//  }

Testing

In order to test you need to install mocha globaly on your machine

$ cd /"module-path"/cc-payment-Encoder
$ mocha

License

Apache-2.0

payment-encoder's People

Contributors

thehobbit85 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.