author liangqin.fan gmail import { BalanceType , TransferBalance } from "../env" ; import { Callable } from "./Callable" ; import { u128 } from "as-bignum" ; import { Codec } from "as-scale-codec" ; import { ReturnCode } from "as-contract-runtime" ; class const BytesCount = 32 ; export class AccountId implements Codec { private _id : Array < u8 > ; constructor ( bytes = [ ] ) { this . _id = new Array < u8 > ( BytesCount ) ; memory . copy ( this . _id . dataStart , bytes . dataStart , BytesCount ) ; } static from ( uarr ) { return new AccountId ( uarr ) ; } transfer ( value ) { TransferBalance ( this . _id , value ) ; } call ( data , gas = 0 , value = u128 . Zero ) { let callable = new Callable ( this . _id ) ; let ret = callable . gas ( gas ) . value ( value ) . data ( data ) . call ( ) ; assert ( ret == ReturnCode . Success , "call external message failed." ) ; return callable . callResult ( ) ; } toU8a ( ) { return this . _id ; } encodedLength ( ) { return BytesCount ; } populateFromBytes ( bytes , index = 0 ) { assert ( bytes . length >= BytesCount , "Can not populate AccountType from bytes." ) ; this . _id = bytes . slice ( index , index + BytesCount ) ; } eq ( other ) { return ( memory . compare ( this . _id . dataStart , other . toU8a ( ) . dataStart , BytesCount ) == 0 ) ; } notEq ( other ) { return ( memory . compare ( this . _id . dataStart , other . toU8a ( ) . dataStart , BytesCount ) != 0 ) ; } toString ( ) { return this . _id . join ( "" ) ; } } export const AccountId0 = new AccountId ( new Array < u8 > ( 32 ) . fill ( 0 ) ) ;