Skip to content

Commit

Permalink
Add mint() to AssetScheme class
Browse files Browse the repository at this point in the history
  • Loading branch information
joojis committed Jun 28, 2018
1 parent 6af52ad commit bec4024
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/AssetTransferAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,18 @@ export class AssetTransferAddress {
const payload = toHex(Buffer.from(bytes.slice(2)));
return new this(type, new H256(payload), address);
}

getLockScriptHashAndParameters(): { lockScriptHash: H256, parameters: Buffer[] } {
const { type, payload } = this;
switch (type) {
case 0x00:
return { lockScriptHash: payload, parameters: [] };
case 0x01:
// FIXME:
const lockScriptHash = new H256("0000000000000000000000000000000000000000000000000000000000000000");
return { lockScriptHash, parameters: [Buffer.from(payload.value, "hex")] };
default:
throw "Unreachable";
}
}
}
14 changes: 14 additions & 0 deletions src/primitives/AssetScheme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { H160 } from ".";
import { AssetTransferAddress } from "../AssetTransferAddress";
import { AssetMintTransaction } from "./transaction/AssetMintTransaction";

export type AssetSchemeData = {
metadata: string;
Expand Down Expand Up @@ -31,4 +33,16 @@ export class AssetScheme {
registrar: registrar === null ? null : registrar.value
};
}

mint(address: AssetTransferAddress, options: { nonce?: number } = {}): AssetMintTransaction {
const { nonce = 0 } = options;
const { metadata, amount, registrar } = this;
return new AssetMintTransaction({
metadata,
registrar,
amount,
nonce,
...address.getLockScriptHashAndParameters(),
});
}
}

0 comments on commit bec4024

Please sign in to comment.