Models¶
plasma-utils
provides several different “models” that represent the various common data structures we use.
These models implement the schemas that we use in serialization.
It’s pretty simple to import all of the available models:
const utils = require('plasma-utils')
const models = utils.serialization.models
Transfer¶
A Transfer
is the basic component of every transaction.
Every transaction has one or more transfers.
const Transfer = models.Transfer
const transfer = new Transfer({
token: 0,
start: 0,
end: 100,
sender: '0x1E3a4a2edec2b3568B5Ad0656ec3b48d9C699dB6',
recipient: '0x8508c8aCA521512D4695eCF6976d2e8D2666a46d'
})
Properties¶
typedStart¶
transfer.typedStart
The “typed” start of the range being transferred.
Calculated by concatenating token
and start
.
Primarily used for calculating state updates in plasma-core
.
Returns¶
BigNum
: The typed start.
typedEnd¶
transfer.typedEnd
The “typed” end of the range being transferred.
Calculated by concatenating token
and end
.
Primarily used for calculating state updates in plasma-core
.
Returns¶
BigNum
: The typed end.
recipient¶
transfer.recipient
Address of the user receiving the transfer.
Returns¶
string
: Recipient address.
UnsignedTransaction¶
An UnsignedTransaction
contains transfers and a block number, but no signatures.
const UnsignedTransaction = models.UnsignedTransaction
const unsigned = new UnsignedTransaction({
block: 123,
transfers: [
{
token: 0,
start: 0,
end: 100,
sender: '0x1E3a4a2edec2b3568B5Ad0656ec3b48d9C699dB6',
recipient: '0x8508c8aCA521512D4695eCF6976d2e8D2666a46d'
}
]
})
Properties¶
block¶
unsigned.block
The block in which this transaction was included.
Returns¶
BigNum
: The transaction block number.
transfers¶
unsigned.transfers
A list of Transfers
that make up this transaction.
Returns¶
Array<Transfer>
: A list of transfers.
encoded¶
unsigned.encoded
The hex-encoded version of this transaction.
Returns¶
string
: Encoded transaction.
SignedTransaction¶
An SignedTransaction
contains transfers, and a block number, and a signature for each transfer.
const SignedTransaction = models.SignedTransaction
const signed = new SignedTransaction({
block: 123,
transfers: [
{
token: 0,
start: 0,
end: 100,
sender: '0x1E3a4a2edec2b3568B5Ad0656ec3b48d9C699dB6',
recipient: '0x8508c8aCA521512D4695eCF6976d2e8D2666a46d'
}
],
signatures: [
{
v: '0x1b',
r: '0xd693b532a80fed6392b428604171fb32fdbf953728a3a7ecc7d4062b1652c042',
s: '0x24e9c602ac800b983b035700a14b23f78a253ab762deab5dc27e3555a750b354'
}
]
})
Properties¶
block¶
signed.block
The block in which this transaction was included.
Returns¶
BigNum
: The transaction block number.
transfers¶
signed.transfers
A list of Transfers
that make up this transaction.
Returns¶
Array<Transfer>
: A list of transfers.
signatures¶
signed.signatures
A list of Signatures
on this transaction.
There should be one signature for each transfer, where the signature is from the sender of the transfer.
Returns¶
Array<Signature>
: A list of signatures.
encoded¶
signed.encoded
The hex-encoded version of this transaction.
Returns¶
string
: Encoded transaction.