Skip to content

Latest commit

 

History

History
159 lines (118 loc) · 6.89 KB

Transaction0.md

File metadata and controls

159 lines (118 loc) · 6.89 KB

Transaction0

Model A signed or unsigned FAT-0 Transaction

Kind: global class
Access: protected

new Transaction(builder)

Param Type Description
builder TransactionBuilder | object Either a TransactionBuilder object or a FAT-0 transaction object content

Example

//From transaction builder
let tx = new TransactionBuilder(tokenChainId)
.input("Fs1q7FHcW4Ti9tngdGAbA3CxMjhyXtNyB1BSdc8uR46jVUVCWtbJ", 150)
.output("FA3aECpw3gEZ7CMQvRNxEtKBGKAos3922oqYLcHQ9NqXHudC6YBM", 150)
.build();

tx.getInputs(); // => {"FA1PkAEbmo1XNangSnxmKqi1PN5sVDbQ6zsnXCsMUejT66WaDgkm":150}

tx.getChainId(); // => "013de826902b7d075f00101649ca4fa7b49b5157cba736b2ca90f67e2ad6e8ec"


//or from API response
const response =
{
    entryhash: '68f3ca3a8c9f7a0cb32dc9717347cb179b63096e051a60ce8be9c292d29795af',
    timestamp: 1550696040,
    data:
        {
            inputs: {FA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MC: 10},
            outputs: {FA3aECpw3gEZ7CMQvRNxEtKBGKAos3922oqYLcHQ9NqXHudC6YBM: 10}
        }
};

tx = new Transaction(response);

tx.getEntryHash(); // => "68f3ca3a8c9f7a0cb32dc9717347cb179b63096e051a60ce8be9c292d29795af"

transaction0.getInputs() ⇒ object

Get the inputs object for the transaction (Map of Address => Token IDs)

Kind: instance method of Transaction0
Returns: object - - The transaction's inputs

transaction0.getOutputs() ⇒ object

Get the outputs object for the transaction (Map of Address => Token IDs)

Kind: instance method of Transaction0
Returns: object - - The transaction's outputs

transaction0.getMetadata() ⇒ *

Get the metadata if present for the transaction if present

Kind: instance method of Transaction0
Returns: * - - The transaction's metadata (if present, undefined if not)

transaction0.isCoinbase() ⇒ boolean

Check whether this transaction is a coinbase (token minting) transaction

Kind: instance method of Transaction0
Returns: boolean - - Whether the transaction is a coinbase transaction or not

transaction0.getEntry() ⇒ Entry

Get the factom-js Entry object representing the signed FAT transaction. Can be submitted directly to Factom

Kind: instance method of Transaction0
Returns: Entry - - Get the Factom-JS Factom entry representation of the transaction, including extids & other signatures
See: https://github.com/PaulBernier/factomjs/blob/master/src/entry.js
Example

const {FactomCli, Entry, Chain} = require('factom');
     const cli = new FactomCli(); // Default factomd connection to localhost:8088 and walletd connection to localhost:8089

     const tokenChainId = '013de826902b7d075f00101649ca4fa7b49b5157cba736b2ca90f67e2ad6e8ec';

     const tx = new TransactionBuilder(tokenChainId)
     .input("Fs1q7FHcW4Ti9tngdGAbA3CxMjhyXtNyB1BSdc8uR46jVUVCWtbJ", 150)
     .output("FA3aECpw3gEZ7CMQvRNxEtKBGKAos3922oqYLcHQ9NqXHudC6YBM", 150)
     .build();

     //"cast" the entry object to prevent compatibility issues
     const entry = Entry.builder(tx.getEntry()).build();

     await cli.add(entry, "Es32PjobTxPTd73dohEFRegMFRLv3X5WZ4FXEwNN8kE2pMDfeMym"); //commit the transaction entry to the token chain

transaction0.getChainId() ⇒ string

Get the token chain ID for this transaction

Kind: instance method of Transaction0
Returns: string - - The chain ID string. Undefined if the transaction is constructed from an object or unsigned

transaction0.getEntryhash() ⇒ string

Get the Factom entryhash of the transaction.

Kind: instance method of Transaction0
Returns: string - - The entryhash of the transaction. Only defined if the Transaction was constructed from an object

transaction0.getTimestamp() ⇒ number

Get the unix timestamp of when the Transaction was signed (locally built transactions) or committed to Factom (from RPC response JSON)

Kind: instance method of Transaction0
Returns: number - - The integer unix timestamp

transaction0.getPending() ⇒ boolean

Get the pending status of the transaction at the time of request.

Kind: instance method of Transaction0
Returns: boolean - - The pending status of the entry in the daemon

transaction0.getMarshalDataSig(inputIndex) ⇒ Buffer

Get the assembled ("marshalled") data that needs to be signed for the transaction for the given input address index

Kind: instance method of Transaction0
Returns: Buffer - - Get the marshalled data that needs to be hashed then signed

Param Type Description
inputIndex number The input index to marshal to prep for hashing then signing

transaction0.validateSignatures() ⇒ boolean

Validate all the signatures in the transaction against the input addresses

Kind: instance method of Transaction0
Returns: boolean - returns true if signatures are valid, throws error otherwise.