Exemple #1
0
void queue_pkt_open(struct peer *peer, OpenChannel__AnchorOffer anchor)
{
	OpenChannel *o = tal(peer, OpenChannel);

	/* Set up out commit info now: rest gets done in setup_first_commit
	 * once anchor is established. */
	peer->us.commit = talz(peer, struct commit_info);
	peer->us.commit->revocation_hash = peer->us.next_revocation_hash;
	peer_get_revocation_hash(peer, 1, &peer->us.next_revocation_hash);

	open_channel__init(o);
	o->revocation_hash = sha256_to_proto(o, &peer->us.commit->revocation_hash);
	o->next_revocation_hash = sha256_to_proto(o, &peer->us.next_revocation_hash);
	o->commit_key = pubkey_to_proto(o, &peer->us.commitkey);
	o->final_key = pubkey_to_proto(o, &peer->us.finalkey);
	o->delay = tal(o, Locktime);
	locktime__init(o->delay);
	o->delay->locktime_case = LOCKTIME__LOCKTIME_SECONDS;
	o->delay->seconds = rel_locktime_to_seconds(&peer->us.locktime);
	o->initial_fee_rate = peer->us.commit_fee_rate;
	if (anchor == OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR)
		assert(peer->us.offer_anchor == CMD_OPEN_WITH_ANCHOR);
	else {
		assert(anchor == OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR);
		assert(peer->us.offer_anchor == CMD_OPEN_WITHOUT_ANCHOR);
	}
		
	o->anch = anchor;
	o->min_depth = peer->us.mindepth;
	queue_pkt(peer, PKT__PKT_OPEN, o);
}
Locktime *rel_locktime_to_proto(const tal_t *ctx,
				const struct rel_locktime *locktime)
{
	Locktime *l = tal(ctx, Locktime);
	locktime__init(l);
	
	if (rel_locktime_is_seconds(locktime)) {
		l->locktime_case = LOCKTIME__LOCKTIME_SECONDS;
		l->seconds = rel_locktime_to_seconds(locktime);
	} else {
		l->locktime_case = LOCKTIME__LOCKTIME_BLOCKS;
		l->blocks = rel_locktime_to_blocks(locktime);
	}
	return l;
}